Bladeren bron

Support styling on back button on iOS (#3755)

* Removed possibleOpenGesture MMOpenDrawerGestureModePanningCenterView possibleOpenGestureModesForGestureRecognizer. This allows swipeable componenets like swipeable lists to be used on iOS.

* Revert "Removed possibleOpenGesture MMOpenDrawerGestureModePanningCenterView possibleOpenGestureModesForGestureRecognizer. This allows swipeable componenets like swipeable lists to be used on iOS."

This reverts commit f2500be9f7.

* Revert "Removed possibleOpenGesture MMOpenDrawerGestureModePanningCenterView possibleOpenGestureModesForGestureRecognizer. This allows swipeable componenets like swipeable lists to be used on iOS."

This reverts commit f2500be9f7.

* Allow styling of default back button on iOS.
Ujwal Setlur 6 jaren geleden
bovenliggende
commit
f2635f1116
2 gewijzigde bestanden met toevoegingen van 29 en 2 verwijderingen
  1. 2
    0
      lib/ios/RNNBackButtonOptions.h
  2. 27
    2
      lib/ios/RNNBackButtonOptions.m

+ 2
- 0
lib/ios/RNNBackButtonOptions.h Bestand weergeven

@@ -8,5 +8,7 @@
8 8
 @property (nonatomic, strong) NSString* transition;
9 9
 @property (nonatomic, strong) NSNumber* showTitle;
10 10
 @property (nonatomic, strong) NSNumber* color;
11
+@property (nonatomic, strong) NSString* fontFamily;
12
+@property (nonatomic, strong) NSNumber* fontSize;
11 13
 
12 14
 @end

+ 27
- 2
lib/ios/RNNBackButtonOptions.m Bestand weergeven

@@ -15,11 +15,36 @@
15 15
 		
16 16
 		UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:nil action:nil];
17 17
 		[self setBackItem:backItem onViewController:viewController];
18
-	} else if (self.title) {
19
-		UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:self.title
18
+	} else {
19
+		NSString *title;
20
+		
21
+		title = self.title ? self.title : viewController.navigationItem.title;
22
+		UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:title
20 23
 																	 style:UIBarButtonItemStylePlain
21 24
 																	target:nil
22 25
 																	action:nil];
26
+
27
+		if (self.color) {
28
+			[backItem setTintColor:[RCTConvert UIColor:self.color]];
29
+		}
30
+
31
+		if(self.fontFamily || self.fontSize) {
32
+			NSNumber* fontSize = self.fontSize;
33
+			NSString* fontFamily = self.fontFamily;
34
+			NSMutableDictionary* textAttributes = [[NSMutableDictionary alloc] init];
35
+			UIFont *font;
36
+
37
+			if (!fontSize) {
38
+				fontSize = [[NSNumber alloc] initWithInt: 18];
39
+			}
40
+			font = fontFamily ? 
41
+				[UIFont fontWithName:fontFamily size:[fontSize floatValue]] : 
42
+				[UIFont systemFontOfSize:[fontSize floatValue]];
43
+			[textAttributes setObject:font forKey:NSFontAttributeName];
44
+
45
+			[backItem setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
46
+			[backItem setTitleTextAttributes:textAttributes forState:UIControlStateHighlighted];
47
+		}
23 48
 		
24 49
 		[self setBackItem:backItem onViewController:viewController];
25 50
 	}