react-native-navigation的迁移库

RNNLayoutOptions.m 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #import "RNNLayoutOptions.h"
  2. #import <React/RCTConvert.h>
  3. #import "UIViewController+RNNOptions.h"
  4. @implementation RNNLayoutOptions
  5. - (instancetype)initWithDict:(NSDictionary *)dict {
  6. self = [super init];
  7. self.backgroundColor = [ColorParser parse:dict key:@"backgroundColor"];
  8. self.componentBackgroundColor = [ColorParser parse:dict key:@"componentBackgroundColor"];
  9. self.direction = [TextParser parse:dict key:@"direction"];
  10. self.orientation = dict[@"orientation"];
  11. return self;
  12. }
  13. - (UIInterfaceOrientationMask)supportedOrientations {
  14. NSArray* orientationsArray = [self.orientation isKindOfClass:[NSString class]] ? @[self.orientation] : self.orientation;
  15. NSUInteger supportedOrientationsMask = 0;
  16. if (!orientationsArray || [self.orientation isEqual:@"default"]) {
  17. return [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]];
  18. } else {
  19. for (NSString* orientation in orientationsArray) {
  20. if ([orientation isEqualToString:@"all"]) {
  21. supportedOrientationsMask = UIInterfaceOrientationMaskAll;
  22. break;
  23. }
  24. if ([orientation isEqualToString:@"landscape"]) {
  25. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskLandscape);
  26. }
  27. if ([orientation isEqualToString:@"portrait"]) {
  28. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortrait);
  29. }
  30. if ([orientation isEqualToString:@"upsideDown"]) {
  31. supportedOrientationsMask = (supportedOrientationsMask | UIInterfaceOrientationMaskPortraitUpsideDown);
  32. }
  33. }
  34. }
  35. return supportedOrientationsMask;
  36. }
  37. @end