Преглед на файлове

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

Ran Greenberg преди 7 години
родител
ревизия
93237a0bc3
променени са 2 файла, в които са добавени 28 реда и са изтрити 17 реда
  1. 2
    1
      docs/top-level-api.md
  2. 26
    16
      ios/RCCManager.m

+ 2
- 1
docs/top-level-api.md Целия файл

@@ -58,7 +58,8 @@ Navigation.startTabBasedApp({
58 58
   appStyle: {
59 59
     orientation: 'portrait', // Sets a specific orientation to the entire app. Default: 'auto'. Supported values: 'auto', 'landscape', 'portrait'
60 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 64
   drawer: { // optional, add this if you want a side menu drawer in your app
64 65
     left: { // optional, define if you want a drawer from the left

+ 26
- 16
ios/RCCManager.m Целия файл

@@ -2,6 +2,7 @@
2 2
 #import "RCCViewController.h"
3 3
 #import <React/RCTBridge.h>
4 4
 #import <React/RCTRedBox.h>
5
+#import <React/RCTConvert.h>
5 6
 #import <Foundation/Foundation.h>
6 7
 
7 8
 @interface RCCManager() <RCTBridgeDelegate>
@@ -17,14 +18,14 @@
17 18
 {
18 19
   static RCCManager *sharedInstance = nil;
19 20
   static dispatch_once_t onceToken = 0;
20
-
21
+  
21 22
   dispatch_once(&onceToken,^{
22 23
     if (sharedInstance == nil)
23 24
     {
24 25
       sharedInstance = [[RCCManager alloc] init];
25 26
     }
26 27
   });
27
-
28
+  
28 29
   return sharedInstance;
29 30
 }
30 31
 
@@ -40,7 +41,7 @@
40 41
   {
41 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 46
   return self;
46 47
 }
@@ -64,22 +65,22 @@
64 65
   {
65 66
     return;
66 67
   }
67
-
68
+  
68 69
   NSMutableDictionary *componentsDic = self.modulesRegistry[componentType];
69 70
   if (componentsDic == nil)
70 71
   {
71 72
     componentsDic = [@{} mutableCopy];
72 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 84
   componentsDic[componentId] = controller;
84 85
 }
85 86
 
@@ -107,15 +108,15 @@
107 108
   {
108 109
     return nil;
109 110
   }
110
-
111
+  
111 112
   id component = nil;
112
-
113
+  
113 114
   NSMutableDictionary *componentsDic = self.modulesRegistry[componentType];
114 115
   if (componentsDic != nil)
115 116
   {
116 117
     component = componentsDic[componentId];
117 118
   }
118
-
119
+  
119 120
   return component;
120 121
 }
121 122
 
@@ -153,7 +154,7 @@
153 154
 -(void)initBridgeWithBundleURL:(NSURL *)bundleURL launchOptions:(NSDictionary *)launchOptions
154 155
 {
155 156
   if (self.sharedBridge) return;
156
-
157
+  
157 158
   self.bundleURL = bundleURL;
158 159
   self.sharedBridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
159 160
   
@@ -248,6 +249,15 @@
248 249
 -(void)setAppStyle:(NSDictionary*)appStyle
249 250
 {
250 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