react-native-navigation的迁移库

RNNNavigationOptions.m 1.2KB

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