1#import <UIKit/UIKit.h>
2
3#import "EXManagedAppSplashScreenConfigurationBuilder.h"
4#import "EXUtil.h"
5
6@import EXManifests;
7
8static const NSString *kManifestIosKey = @"ios";
9static const NSString *kManifestSplashKey = @"splash";
10static const NSString *kManifestResizeModeKey = @"resizeMode";
11static const NSString *kManifestBackgroundColorKey = @"backgroundColor";
12static const NSString *kManifestTabletImageUrlKey = @"tabletImageUrl";
13static const NSString *kManifestImageUrlKey = @"imageUrl";
14
15static const NSString *kImageResizeModeContain = @"contain";
16static const NSString *kImageResizeModeCover = @"cover";
17
18@implementation EXManagedAppSplashScreenConfigurationBuilder
19
20+ (EXManagedAppSplashScreenConfiguration *)parseManifest:(EXManifestsManifest *)manifest
21{
22  UIColor *backgroundColor = [[self class] parseBackgroundColor:manifest];
23  NSString *imageUrl = [[self class] parseImageUrl:manifest];
24  EXSplashScreenImageResizeMode imageResizeMode = [[self class] parseImageResizeMode:manifest];
25  return [[EXManagedAppSplashScreenConfiguration alloc] initWithBackgroundColor:backgroundColor
26                                                                       imageUrl:imageUrl
27                                                                imageResizeMode:imageResizeMode];
28}
29
30+ (UIColor * _Nonnull)parseBackgroundColor:(EXManifestsManifest *)manifest
31{
32  // TODO: (@bbarthec) backgroundColor is recommended to be in HEX format for now, but it should be any css-valid format
33  NSString *hexString = manifest.iosSplashBackgroundColor;
34  UIColor *color = [EXUtil colorWithHexString:hexString];
35  if (color) {
36    return color;
37  }
38
39  return [UIColor whiteColor];
40}
41
42+ (NSString * _Nullable)parseImageUrl:(EXManifestsManifest *)manifest
43{
44  return manifest.iosSplashImageUrl;
45}
46
47+ (EXSplashScreenImageResizeMode)parseImageResizeMode:(EXManifestsManifest *)manifest
48{
49  NSString *resizeMode = manifest.iosSplashImageResizeMode;
50  if ([kImageResizeModeCover isEqualToString:resizeMode]) {
51    return EXSplashScreenImageResizeModeCover;
52  }
53  return EXSplashScreenImageResizeModeContain;
54}
55
56@end
57