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