Browse Source

add backButtonImage to app style in order to custom the default back button arrow image with provided image (#1834)

Ran Greenberg 7 years ago
parent
commit
93237a0bc3
2 changed files with 28 additions and 17 deletions
  1. 2
    1
      docs/top-level-api.md
  2. 26
    16
      ios/RCCManager.m

+ 2
- 1
docs/top-level-api.md View File

58
   appStyle: {
58
   appStyle: {
59
     orientation: 'portrait', // Sets a specific orientation to the entire app. Default: 'auto'. Supported values: 'auto', 'landscape', 'portrait'
59
     orientation: 'portrait', // Sets a specific orientation to the entire app. Default: 'auto'. Supported values: 'auto', 'landscape', 'portrait'
60
     bottomTabBadgeTextColor: 'red', // Optional, change badge text color. Android only
60
     bottomTabBadgeTextColor: 'red', // Optional, change badge text color. Android only
61
-    bottomTabBadgeBackgroundColor: 'green' // Optional, change badge background color. Android only
61
+    bottomTabBadgeBackgroundColor: 'green', // Optional, change badge background color. Android only
62
+    backButtonImage: require('./pathToImage.png') // Change the back button default arrow image with provided image. iOS only
62
   },
63
   },
63
   drawer: { // optional, add this if you want a side menu drawer in your app
64
   drawer: { // optional, add this if you want a side menu drawer in your app
64
     left: { // optional, define if you want a drawer from the left
65
     left: { // optional, define if you want a drawer from the left

+ 26
- 16
ios/RCCManager.m View File

2
 #import "RCCViewController.h"
2
 #import "RCCViewController.h"
3
 #import <React/RCTBridge.h>
3
 #import <React/RCTBridge.h>
4
 #import <React/RCTRedBox.h>
4
 #import <React/RCTRedBox.h>
5
+#import <React/RCTConvert.h>
5
 #import <Foundation/Foundation.h>
6
 #import <Foundation/Foundation.h>
6
 
7
 
7
 @interface RCCManager() <RCTBridgeDelegate>
8
 @interface RCCManager() <RCTBridgeDelegate>
17
 {
18
 {
18
   static RCCManager *sharedInstance = nil;
19
   static RCCManager *sharedInstance = nil;
19
   static dispatch_once_t onceToken = 0;
20
   static dispatch_once_t onceToken = 0;
20
-
21
+  
21
   dispatch_once(&onceToken,^{
22
   dispatch_once(&onceToken,^{
22
     if (sharedInstance == nil)
23
     if (sharedInstance == nil)
23
     {
24
     {
24
       sharedInstance = [[RCCManager alloc] init];
25
       sharedInstance = [[RCCManager alloc] init];
25
     }
26
     }
26
   });
27
   });
27
-
28
+  
28
   return sharedInstance;
29
   return sharedInstance;
29
 }
30
 }
30
 
31
 
40
   {
41
   {
41
     self.modulesRegistry = [@{} mutableCopy];
42
     self.modulesRegistry = [@{} mutableCopy];
42
     
43
     
43
-//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onRNReload) name:RCTReloadNotification object:nil];
44
+    //    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onRNReload) name:RCTReloadNotification object:nil];
44
   }
45
   }
45
   return self;
46
   return self;
46
 }
47
 }
64
   {
65
   {
65
     return;
66
     return;
66
   }
67
   }
67
-
68
+  
68
   NSMutableDictionary *componentsDic = self.modulesRegistry[componentType];
69
   NSMutableDictionary *componentsDic = self.modulesRegistry[componentType];
69
   if (componentsDic == nil)
70
   if (componentsDic == nil)
70
   {
71
   {
71
     componentsDic = [@{} mutableCopy];
72
     componentsDic = [@{} mutableCopy];
72
     self.modulesRegistry[componentType] = componentsDic;
73
     self.modulesRegistry[componentType] = componentsDic;
73
   }
74
   }
74
-
75
+  
75
   /*
76
   /*
76
-  TODO: we really want this error, but we need to unregister controllers when they dealloc
77
-  if (componentsDic[componentId])
78
-  {
79
-    [self.sharedBridge.redBox showErrorMessage:[NSString stringWithFormat:@"Controllers: controller with id %@ is already registered. Make sure all of the controller id's you use are unique.", componentId]];
80
-  }
81
-  */
82
-   
77
+   TODO: we really want this error, but we need to unregister controllers when they dealloc
78
+   if (componentsDic[componentId])
79
+   {
80
+   [self.sharedBridge.redBox showErrorMessage:[NSString stringWithFormat:@"Controllers: controller with id %@ is already registered. Make sure all of the controller id's you use are unique.", componentId]];
81
+   }
82
+   */
83
+  
83
   componentsDic[componentId] = controller;
84
   componentsDic[componentId] = controller;
84
 }
85
 }
85
 
86
 
107
   {
108
   {
108
     return nil;
109
     return nil;
109
   }
110
   }
110
-
111
+  
111
   id component = nil;
112
   id component = nil;
112
-
113
+  
113
   NSMutableDictionary *componentsDic = self.modulesRegistry[componentType];
114
   NSMutableDictionary *componentsDic = self.modulesRegistry[componentType];
114
   if (componentsDic != nil)
115
   if (componentsDic != nil)
115
   {
116
   {
116
     component = componentsDic[componentId];
117
     component = componentsDic[componentId];
117
   }
118
   }
118
-
119
+  
119
   return component;
120
   return component;
120
 }
121
 }
121
 
122
 
153
 -(void)initBridgeWithBundleURL:(NSURL *)bundleURL launchOptions:(NSDictionary *)launchOptions
154
 -(void)initBridgeWithBundleURL:(NSURL *)bundleURL launchOptions:(NSDictionary *)launchOptions
154
 {
155
 {
155
   if (self.sharedBridge) return;
156
   if (self.sharedBridge) return;
156
-
157
+  
157
   self.bundleURL = bundleURL;
158
   self.bundleURL = bundleURL;
158
   self.sharedBridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
159
   self.sharedBridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
159
   
160
   
248
 -(void)setAppStyle:(NSDictionary*)appStyle
249
 -(void)setAppStyle:(NSDictionary*)appStyle
249
 {
250
 {
250
   self.globalAppStyle = [NSDictionary dictionaryWithDictionary:appStyle];
251
   self.globalAppStyle = [NSDictionary dictionaryWithDictionary:appStyle];
252
+  [self applyAppStyle];
253
+  
254
+}
255
+
256
+-(void)applyAppStyle {
257
+  id backButtonImage = self.globalAppStyle[@"backButtonImage"];
258
+  UIImage *image = backButtonImage ? [RCTConvert UIImage:backButtonImage] : nil;
259
+  [[UINavigationBar appearance] setBackIndicatorImage:image];
260
+  [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:image];
251
 }
261
 }
252
 
262
 
253
 
263