react-native-navigation的迁移库

RNNNavigationOptions.m 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #import "RNNNavigationOptions.h"
  2. #import <React/RCTConvert.h>
  3. @implementation RNNNavigationOptions
  4. -(instancetype)init {
  5. return [self initWithDict:@{}];
  6. }
  7. -(instancetype)initWithDict:(NSDictionary *)navigationOptions {
  8. if(self = [super init]) {
  9. self.topBarBackgroundColor = [navigationOptions objectForKey:@"topBarBackgroundColor"];
  10. self.statusBarHidden = [navigationOptions objectForKey:@"statusBarHidden"];
  11. self.title = [navigationOptions objectForKey:@"title"];
  12. self.topBarTextColor = [navigationOptions objectForKey:@"topBarTextColor"];
  13. }
  14. return self;
  15. }
  16. -(void)mergeWith:(NSDictionary *)otherOptions {
  17. for (id key in otherOptions) {
  18. [self setValue:[otherOptions objectForKey:key] forKey:key];
  19. }
  20. }
  21. -(void)applyOn:(UIViewController*)viewController{
  22. if (self.topBarBackgroundColor) {
  23. UIColor* backgroundColor = [RCTConvert UIColor:self.topBarBackgroundColor];
  24. viewController.navigationController.navigationBar.barTintColor = backgroundColor;
  25. }
  26. if (self.title) {
  27. viewController.navigationItem.title = self.title;
  28. }
  29. if (self.topBarTextColor) {
  30. UIColor* textColor = [RCTConvert UIColor:self.topBarTextColor];
  31. viewController.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:textColor};
  32. }
  33. }
  34. @end