Kaynağa Gözat

fixes custom buttons (#3918)

Yogev Ben David 6 yıl önce
ebeveyn
işleme
a612f7fb17
No account linked to committer's email address

+ 7
- 0
e2e/ScreenStyle.test.js Dosyayı Görüntüle

@@ -124,6 +124,13 @@ describe('screen style', () => {
124 124
     await expect(elementByLabel(`Two`)).toExist();
125 125
   });
126 126
 
127
+  test('custom button is tapable', async () => {
128
+    await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
129
+    await expect(elementByLabel(`Two`)).toExist();
130
+    await elementByLabel(`Two`).tap();
131
+    await expect(elementByLabel(`Thanks for that :)`)).toExist();
132
+  });
133
+
127 134
   test('tab bar items visibility', async () => {
128 135
     await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
129 136
     await expect(elementById(testIDs.FIRST_TAB_BAR_BUTTON)).toBeVisible();

+ 1
- 1
lib/ios/RNNNavigationButtons.m Dosyayı Görüntüle

@@ -78,7 +78,7 @@
78 78
 	
79 79
 	RNNUIBarButtonItem *barButtonItem;
80 80
 	if (component) {
81
-		RCTRootView *view = (RCTRootView*)[self.viewController.creator createRootView:component[@"name"] rootViewId:component[@"componentId"]];
81
+		RCTRootView *view = (RCTRootView*)[self.viewController.creator createCustomReactView:component[@"name"] rootViewId:component[@"componentId"]];
82 82
 		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withCustomView:view];
83 83
 	} else if (iconImage) {
84 84
 		barButtonItem = [[RNNUIBarButtonItem alloc] init:buttonId withIcon:iconImage];

+ 2
- 7
lib/ios/RNNReactRootView.h Dosyayı Görüntüle

@@ -1,11 +1,6 @@
1 1
 #import <UIKit/UIKit.h>
2
-#import <React/RCTRootView.h>
3
-#import <React/RCTRootViewDelegate.h>
2
+#import "RNNReactView.h"
4 3
 
5
-@interface RNNReactRootView : RCTRootView <RCTRootViewDelegate>
6
-
7
-@property (nonatomic, copy) void (^rootViewDidChangeIntrinsicSize)(CGSize intrinsicSize);
8
-
9
-- (void)setAlignment:(NSString*)alignment;
4
+@interface RNNReactRootView : RNNReactView
10 5
 
11 6
 @end

+ 5
- 40
lib/ios/RNNReactRootView.m Dosyayı Görüntüle

@@ -2,50 +2,15 @@
2 2
 #import "RCTHelpers.h"
3 3
 #import <React/RCTUIManager.h>
4 4
 
5
-@implementation RNNReactRootView {
6
-	RCTBridge* _bridge;
7
-};
5
+@implementation RNNReactRootView
8 6
 
9
-- (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties {
10
-	self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
11
-	_bridge = bridge;
12
-	
13
-#ifdef DEBUG
14
-	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentDidAppear:) name:RCTContentDidAppearNotification object:nil];
15
-#endif
16
-	
17
-	return self;
7
+- (void)layoutSubviews {
8
+	[super layoutSubviews];
9
+	[self.bridge.uiManager setSize:self.bounds.size forView:self];
18 10
 }
19 11
 
20 12
 - (void)contentDidAppear:(NSNotification *)notification {
21
-	if ([((RNNReactRootView *)notification.object).moduleName isEqualToString:self.moduleName]) {
22
-		[RCTHelpers removeYellowBox:self];
23
-		[[NSNotificationCenter defaultCenter] removeObserver:self];
24
-	}
25
-}
26
-
27
-- (void)setRootViewDidChangeIntrinsicSize:(void (^)(CGSize))rootViewDidChangeIntrinsicSize {
28
-	_rootViewDidChangeIntrinsicSize = rootViewDidChangeIntrinsicSize;
29
-	self.delegate = self;
30
-}
31
-
32
-- (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
33
-	if (_rootViewDidChangeIntrinsicSize) {
34
-		_rootViewDidChangeIntrinsicSize(rootView.intrinsicContentSize);
35
-	}
36
-}
37
-
38
-- (void)setAlignment:(NSString *)alignment {
39
-	if ([alignment isEqualToString:@"fill"]) {
40
-		self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
41
-	} else {
42
-		self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
43
-	}
44
-}
45
-
46
-- (void)layoutSubviews {
47
-	[super layoutSubviews];
48
-	[_bridge.uiManager setSize:self.bounds.size forView:self];
13
+	
49 14
 }
50 15
 
51 16
 @end

+ 13
- 1
lib/ios/RNNReactRootViewCreator.m Dosyayı Görüntüle

@@ -1,6 +1,7 @@
1 1
 
2 2
 #import "RNNReactRootViewCreator.h"
3 3
 #import "RNNReactRootView.h"
4
+#import "RNNReactView.h"
4 5
 
5 6
 @implementation RNNReactRootViewCreator {
6 7
 	RCTBridge *_bridge;
@@ -26,8 +27,19 @@
26 27
 	return view;
27 28
 }
28 29
 
30
+- (UIView*)createCustomReactView:(NSString*)name rootViewId:(NSString*)rootViewId {
31
+	if (!rootViewId) {
32
+		@throw [NSException exceptionWithName:@"MissingViewId" reason:@"Missing view id" userInfo:nil];
33
+	}
34
+	
35
+	UIView *view = [[RNNReactView alloc] initWithBridge:_bridge
36
+												 moduleName:name
37
+										  initialProperties:@{@"componentId": rootViewId}];
38
+	return view;
39
+}
40
+
29 41
 -(UIView*)createRootViewFromComponentOptions:(RNNComponentOptions*)componentOptions {
30
-	return [self createRootView:componentOptions.name rootViewId:componentOptions.componentId];
42
+	return [self createCustomReactView:componentOptions.name rootViewId:componentOptions.componentId];
31 43
 }
32 44
 
33 45
 @end

+ 10
- 0
lib/ios/RNNReactView.h Dosyayı Görüntüle

@@ -0,0 +1,10 @@
1
+#import <React/RCTRootView.h>
2
+#import <React/RCTRootViewDelegate.h>
3
+
4
+@interface RNNReactView : RCTRootView <RCTRootViewDelegate>
5
+
6
+@property (nonatomic, copy) void (^rootViewDidChangeIntrinsicSize)(CGSize intrinsicSize);
7
+
8
+- (void)setAlignment:(NSString *)alignment;
9
+
10
+@end

+ 42
- 0
lib/ios/RNNReactView.m Dosyayı Görüntüle

@@ -0,0 +1,42 @@
1
+#import "RNNReactView.h"
2
+#import "RCTHelpers.h"
3
+
4
+@implementation RNNReactView
5
+
6
+- (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties {
7
+	self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
8
+	
9
+#ifdef DEBUG
10
+	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentDidAppear:) name:RCTContentDidAppearNotification object:nil];
11
+#endif
12
+	
13
+	return self;
14
+}
15
+
16
+- (void)contentDidAppear:(NSNotification *)notification {
17
+	if ([((RNNReactView *)notification.object).moduleName isEqualToString:self.moduleName]) {
18
+		[RCTHelpers removeYellowBox:self];
19
+		[[NSNotificationCenter defaultCenter] removeObserver:self];
20
+	}
21
+}
22
+
23
+- (void)setRootViewDidChangeIntrinsicSize:(void (^)(CGSize))rootViewDidChangeIntrinsicSize {
24
+	_rootViewDidChangeIntrinsicSize = rootViewDidChangeIntrinsicSize;
25
+	self.delegate = self;
26
+}
27
+
28
+- (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
29
+	if (_rootViewDidChangeIntrinsicSize) {
30
+		_rootViewDidChangeIntrinsicSize(rootView.intrinsicContentSize);
31
+	}
32
+}
33
+
34
+- (void)setAlignment:(NSString *)alignment {
35
+	if ([alignment isEqualToString:@"fill"]) {
36
+		self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
37
+	} else {
38
+		self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
39
+	}
40
+}
41
+
42
+@end

+ 4
- 5
lib/ios/RNNRootViewController.m Dosyayı Görüntüle

@@ -1,13 +1,12 @@
1
-
2 1
 #import "RNNRootViewController.h"
3 2
 #import <React/RCTConvert.h>
4 3
 #import "RNNAnimator.h"
5 4
 #import "RNNCustomTitleView.h"
6 5
 #import "RNNPushAnimation.h"
7
-#import "RNNReactRootView.h"
6
+#import "RNNReactView.h"
8 7
 
9 8
 @interface RNNRootViewController() {
10
-	RNNReactRootView* _customTitleView;
9
+	RNNReactView* _customTitleView;
11 10
 	UIView* _customTopBar;
12 11
 	UIView* _customTopBarBackground;
13 12
 	BOOL _isBeingPresented;
@@ -141,11 +140,11 @@
141 140
 - (void)setCustomNavigationTitleView {
142 141
 	if (!_customTitleView && _isBeingPresented) {
143 142
 		if (self.options.topBar.title.component.name) {
144
-			_customTitleView = (RNNReactRootView*)[_creator createRootViewFromComponentOptions:self.options.topBar.title.component];
143
+			_customTitleView = (RNNReactView*)[_creator createRootViewFromComponentOptions:self.options.topBar.title.component];
145 144
 			_customTitleView.backgroundColor = UIColor.clearColor;
146 145
 			[_customTitleView setAlignment:self.options.topBar.title.component.alignment];
147 146
 			BOOL isCenter = [self.options.topBar.title.component.alignment isEqualToString:@"center"];
148
-			__weak RNNReactRootView *weakTitleView = _customTitleView;
147
+			__weak RNNReactView *weakTitleView = _customTitleView;
149 148
 			CGRect frame = self.navigationController.navigationBar.bounds;
150 149
 			[_customTitleView setFrame:frame];
151 150
 			[_customTitleView setRootViewDidChangeIntrinsicSize:^(CGSize intrinsicContentSize) {

+ 4
- 2
lib/ios/RNNRootViewCreator.h Dosyayı Görüntüle

@@ -4,9 +4,11 @@
4 4
 
5 5
 @protocol RNNRootViewCreator
6 6
 
7
--(UIView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId;
7
+- (UIView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId;
8 8
 
9
--(UIView*)createRootViewFromComponentOptions:(RNNComponentOptions*)componentOptions;
9
+- (UIView*)createRootViewFromComponentOptions:(RNNComponentOptions*)componentOptions;
10
+
11
+- (UIView*)createCustomReactView:(NSString*)name rootViewId:(NSString*)rootViewId;
10 12
 
11 13
 @end
12 14
 

+ 8
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj Dosyayı Görüntüle

@@ -67,6 +67,8 @@
67 67
 		5016E8F020209690009D4F7C /* RNNCustomTitleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5016E8EE2020968F009D4F7C /* RNNCustomTitleView.m */; };
68 68
 		50175CD1207A2AA1004FE91B /* RNNComponentOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50175CCF207A2AA1004FE91B /* RNNComponentOptions.h */; };
69 69
 		50175CD2207A2AA1004FE91B /* RNNComponentOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50175CD0207A2AA1004FE91B /* RNNComponentOptions.m */; };
70
+		501E0217213E7EA3003365C5 /* RNNReactView.h in Headers */ = {isa = PBXBuildFile; fileRef = 501E0215213E7EA3003365C5 /* RNNReactView.h */; };
71
+		501E0218213E7EA3003365C5 /* RNNReactView.m in Sources */ = {isa = PBXBuildFile; fileRef = 501E0216213E7EA3003365C5 /* RNNReactView.m */; };
70 72
 		50220F48212ABDFD004C2B0A /* RNNReactRootView.h in Headers */ = {isa = PBXBuildFile; fileRef = 50220F46212ABDFD004C2B0A /* RNNReactRootView.h */; };
71 73
 		50220F49212ABDFD004C2B0A /* RNNReactRootView.m in Sources */ = {isa = PBXBuildFile; fileRef = 50220F47212ABDFD004C2B0A /* RNNReactRootView.m */; };
72 74
 		502CB43A20CBCA180019B2FE /* RNNBridgeManagerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 502CB43920CBCA140019B2FE /* RNNBridgeManagerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -293,6 +295,8 @@
293 295
 		5016E8EE2020968F009D4F7C /* RNNCustomTitleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNCustomTitleView.m; sourceTree = "<group>"; };
294 296
 		50175CCF207A2AA1004FE91B /* RNNComponentOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNComponentOptions.h; sourceTree = "<group>"; };
295 297
 		50175CD0207A2AA1004FE91B /* RNNComponentOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNComponentOptions.m; sourceTree = "<group>"; };
298
+		501E0215213E7EA3003365C5 /* RNNReactView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNReactView.h; sourceTree = "<group>"; };
299
+		501E0216213E7EA3003365C5 /* RNNReactView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNReactView.m; sourceTree = "<group>"; };
296 300
 		50220F46212ABDFD004C2B0A /* RNNReactRootView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNReactRootView.h; sourceTree = "<group>"; };
297 301
 		50220F47212ABDFD004C2B0A /* RNNReactRootView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNReactRootView.m; sourceTree = "<group>"; };
298 302
 		502CB43920CBCA140019B2FE /* RNNBridgeManagerDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNBridgeManagerDelegate.h; sourceTree = "<group>"; };
@@ -648,6 +652,8 @@
648 652
 				50570BE82063E09B006A1B5C /* RNNTitleViewHelper.h */,
649 653
 				50220F46212ABDFD004C2B0A /* RNNReactRootView.h */,
650 654
 				50220F47212ABDFD004C2B0A /* RNNReactRootView.m */,
655
+				501E0215213E7EA3003365C5 /* RNNReactView.h */,
656
+				501E0216213E7EA3003365C5 /* RNNReactView.m */,
651 657
 				50570BE92063E09B006A1B5C /* RNNTitleViewHelper.m */,
652 658
 				26916C941E4B9CCC00D13680 /* RNNRootViewCreator.h */,
653 659
 				26916C961E4B9E7700D13680 /* RNNReactRootViewCreator.h */,
@@ -898,6 +904,7 @@
898 904
 				50220F48212ABDFD004C2B0A /* RNNReactRootView.h in Headers */,
899 905
 				2DCD9195200014A900EDC75D /* RNNBridgeManager.h in Headers */,
900 906
 				7B1126A91E2D2B6C00F9B03B /* RNNControllerFactory.h in Headers */,
907
+				501E0217213E7EA3003365C5 /* RNNReactView.h in Headers */,
901 908
 				263905D61E4C94970023D7D3 /* RNNSideMenuController.h in Headers */,
902 909
 				263905C81E4C6F440023D7D3 /* SidebarFlipboardAnimation.h in Headers */,
903 910
 				7BEF0D1C1E43771B003E96B0 /* RNNLayoutNode.h in Headers */,
@@ -1035,6 +1042,7 @@
1035 1042
 				E8DA24411F97459B00CD552B /* RNNElementFinder.m in Sources */,
1036 1043
 				50570B272061473D006A1B5C /* RNNTitleOptions.m in Sources */,
1037 1044
 				263905BF1E4C6F440023D7D3 /* RCCTheSideBarManagerViewController.m in Sources */,
1045
+				501E0218213E7EA3003365C5 /* RNNReactView.m in Sources */,
1038 1046
 				50BE951220B5A787004F5DF5 /* RNNStatusBarOptions.m in Sources */,
1039 1047
 				7B1126A01E2D263F00F9B03B /* RNNEventEmitter.m in Sources */,
1040 1048
 				A7626BFD1FC2FB2C00492FB8 /* RNNTopBarOptions.m in Sources */,