Skip to content

Commit 763fe34

Browse files
authored
Merge pull request #1804 from jw2175/refactor-miniappview
[iOS] Refactor miniappview init
2 parents 654021e + 7bacb9c commit 763fe34

File tree

4 files changed

+140
-24
lines changed

4 files changed

+140
-24
lines changed

ern-container-gen-ios/src/hull/ElectrodeContainer/ElectrodeReactNative.h

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,34 +125,55 @@ NS_ASSUME_NONNULL_BEGIN
125125
@return A UIViewController containing the view of the miniapp.
126126
*/
127127
- (UIViewController *)miniAppWithName:(NSString *)name
128-
properties:(NSDictionary * _Nullable)properties;
128+
properties:(NSDictionary * _Nullable)properties
129+
__attribute((deprecated("use -miniAppWithName:properties:overlay:sizeFlexibility:delegate instead")));
129130

130131
/**
131-
Returns a react native miniapp (from a JSBundle).
132+
Returns a react native miniapp (from a JSBundle) inside a view controller.
133+
134+
@param name The name of the mini app, preferably the same name as the jsbundle
135+
without the extension.
136+
@param properties Any configuration to set up the mini app with.
137+
@param overlay determines if view should be rendered as an overlay.
138+
@param sizeFlexibilty defines size flexibility type of the root view
139+
@param delegate the object to register as the miniapp's delegate.
140+
@return A UIViewController containing the view of the miniapp.
141+
*/
142+
- (UIViewController *)miniAppWithName:(NSString *)name
143+
properties:(NSDictionary *_Nullable)properties
144+
overlay:(BOOL)overlay
145+
sizeFlexibility:(NSInteger)sizeFlexibility
146+
delegate:(id<MiniAppViewDelegate> _Nullable)delegate;
147+
148+
/**
149+
Returns a react native miniapp (from a JSBundle) inside a view.
132150
133151
@param name The name of the mini app, preferably the same name as the jsbundle
134152
without the extension.
135153
@param properties Any configuration to set up the mini app with.
136154
@return a UIView of the miniapp.
137155
*/
138156
- (UIView *)miniAppViewWithName:(NSString *)name
139-
properties:(NSDictionary *_Nullable)properties;
157+
properties:(NSDictionary *_Nullable)properties
158+
__attribute((deprecated("use -miniAppViewWithName:properties:overlay:sizeFlexibility:delegate instead")));
140159

141160
/**
142-
Returns a react native miniapp (from a JSBundle).
161+
Returns a react native miniapp (from a JSBundle) inside a view.
143162
144163
@param name The name of the mini app, preferably the same name as the jsbundle
145164
without the extension.
146-
@param overlay Boolean determines if view should be rendered as an overlay.
165+
@param overlay determines if view should be rendered as an overlay.
147166
@param properties Any configuration to set up the mini app with.
148167
@return a UIView of the miniapp.
149168
*/
150169
- (UIView *)miniAppViewWithName:(NSString *)name
151170
properties:(NSDictionary *_Nullable)properties
152-
overlay:(BOOL)overlay;
171+
overlay:(BOOL)overlay
172+
__attribute((deprecated("use -miniAppViewWithName:properties:overlay:sizeFlexibility:delegate instead")));
173+
153174

154175
/**
155-
Returns a react native miniapp (from a JSBundle).
176+
Returns a react native miniapp (from a JSBundle) inside a view.
156177
157178
@param name The name of the mini app, that is registered with the AppComponent.
158179
@param properties initialprops for a React Native miniapp.
@@ -162,10 +183,10 @@ without the extension.
162183
- (UIView *)miniAppViewWithName:(NSString *)name
163184
properties:(NSDictionary *_Nullable)properties
164185
sizeFlexibility:(NSInteger)sizeFlexibilty
165-
__attribute((deprecated("use -miniAppViewWithName:properties:sizeFlexibility:delegate instead")));
186+
__attribute((deprecated("use -miniAppViewWithName:properties:overlay:sizeFlexibility:delegate instead")));
166187

167188
/**
168-
Returns a react native miniapp (from a JSBundle).
189+
Returns a react native miniapp (from a JSBundle) inside a view.
169190
170191
@param name The name of the mini app, that is registered with the AppComponent.
171192
@param properties initialprops for a React Native miniapp.
@@ -176,6 +197,23 @@ without the extension.
176197
- (UIView *)miniAppViewWithName:(NSString *)name
177198
properties:(NSDictionary *_Nullable)properties
178199
sizeFlexibility:(NSInteger)sizeFlexibilty
200+
delegate:(id<MiniAppViewDelegate> _Nullable)delegate
201+
__attribute((deprecated("use -miniAppViewWithName:properties:overlay:sizeFlexibility:delegate instead")));
202+
203+
/**
204+
Returns a react native miniapp (from a JSBundle) inside a view.
205+
206+
@param name The name of the mini app, that is registered with the AppComponent.
207+
@param properties initialprops for a React Native miniapp.
208+
@param overlay determines if view should be rendered as an overlay.
209+
@param sizeFlexibilty defines size flexibility type of the root view
210+
@param delegate the object to register as the miniapp's delegate.
211+
@return a UIView of the miniapp.
212+
*/
213+
- (UIView *)miniAppViewWithName:(NSString *)name
214+
properties:(NSDictionary *_Nullable)properties
215+
overlay:(BOOL)overlay
216+
sizeFlexibility:(NSInteger)sizeFlexibility
179217
delegate:(id<MiniAppViewDelegate> _Nullable)delegate;
180218

181219
/**

ern-container-gen-ios/src/hull/ElectrodeContainer/ElectrodeReactNative.m

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,27 @@ - (UIViewController *)miniAppWithName:(NSString *)name
193193
properties:(NSDictionary *_Nullable)properties
194194
{
195195
UIViewController *miniAppViewController = [UIViewController new];
196-
miniAppViewController.view = [self miniAppViewWithName:name properties:properties];;
196+
miniAppViewController.view = [self miniAppViewWithName:name properties:properties];
197+
return miniAppViewController;
198+
}
197199

200+
- (UIViewController *)miniAppWithName:(NSString *)name
201+
properties:(NSDictionary *_Nullable)properties
202+
overlay:(BOOL)overlay
203+
sizeFlexibility:(NSInteger)sizeFlexibility
204+
delegate:(id<MiniAppViewDelegate> _Nullable)delegate {
205+
UIViewController *miniAppViewController = [UIViewController new];
206+
miniAppViewController.view = [self miniAppViewWithName:name properties:properties overlay:overlay sizeFlexibility:sizeFlexibility delegate:delegate];
198207
return miniAppViewController;
199208
}
200209

201210
- (UIView *)miniAppViewWithName:(NSString *)name properties:(NSDictionary *_Nullable)properties {
202-
// Use the bridge to generate the view
203211
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge moduleName:name initialProperties:properties];
204212
rootView.backgroundColor = [self rootViewColorWithOverlay:NO];
205213
return rootView;
206214
}
207215

208216
- (UIView *)miniAppViewWithName:(NSString *)name properties:(NSDictionary *_Nullable)properties overlay:(BOOL)overlay {
209-
// Use the bridge to generate the view
210217
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge moduleName:name initialProperties:properties];
211218
rootView.backgroundColor = [self rootViewColorWithOverlay:overlay];
212219
return rootView;
@@ -232,6 +239,19 @@ - (UIView *)miniAppViewWithName:(NSString *)name
232239
return rootView;
233240
}
234241

242+
- (UIView *)miniAppViewWithName:(NSString *)name
243+
properties:(NSDictionary *_Nullable)properties
244+
overlay:(BOOL)overlay
245+
sizeFlexibility:(NSInteger)sizeFlexibility
246+
delegate:(id<MiniAppViewDelegate> _Nullable)delegate {
247+
// Use the bridge to generate the view
248+
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge moduleName:name initialProperties:properties];
249+
rootView.sizeFlexibility = (RCTRootViewSizeFlexibility)sizeFlexibility;
250+
rootView.backgroundColor = [self rootViewColorWithOverlay:overlay];
251+
rootView.delegate = delegate;
252+
return rootView;
253+
}
254+
235255
- (UIColor *)rootViewColorWithOverlay:(BOOL)overlay {
236256
if (overlay) {
237257
return [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:0.5];

system-tests/fixtures/ios-container/ElectrodeContainer/ElectrodeReactNative.h

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,34 +89,55 @@ NS_ASSUME_NONNULL_BEGIN
8989
@return A UIViewController containing the view of the miniapp.
9090
*/
9191
- (UIViewController *)miniAppWithName:(NSString *)name
92-
properties:(NSDictionary * _Nullable)properties;
92+
properties:(NSDictionary * _Nullable)properties
93+
__attribute((deprecated("use -miniAppWithName:properties:overlay:sizeFlexibility:delegate instead")));
9394

9495
/**
95-
Returns a react native miniapp (from a JSBundle).
96+
Returns a react native miniapp (from a JSBundle) inside a view controller.
97+
98+
@param name The name of the mini app, preferably the same name as the jsbundle
99+
without the extension.
100+
@param properties Any configuration to set up the mini app with.
101+
@param overlay determines if view should be rendered as an overlay.
102+
@param sizeFlexibilty defines size flexibility type of the root view
103+
@param delegate the object to register as the miniapp's delegate.
104+
@return A UIViewController containing the view of the miniapp.
105+
*/
106+
- (UIViewController *)miniAppWithName:(NSString *)name
107+
properties:(NSDictionary *_Nullable)properties
108+
overlay:(BOOL)overlay
109+
sizeFlexibility:(NSInteger)sizeFlexibility
110+
delegate:(id<MiniAppViewDelegate> _Nullable)delegate;
111+
112+
/**
113+
Returns a react native miniapp (from a JSBundle) inside a view.
96114
97115
@param name The name of the mini app, preferably the same name as the jsbundle
98116
without the extension.
99117
@param properties Any configuration to set up the mini app with.
100118
@return a UIView of the miniapp.
101119
*/
102120
- (UIView *)miniAppViewWithName:(NSString *)name
103-
properties:(NSDictionary *_Nullable)properties;
121+
properties:(NSDictionary *_Nullable)properties
122+
__attribute((deprecated("use -miniAppViewWithName:properties:overlay:sizeFlexibility:delegate instead")));
104123

105124
/**
106-
Returns a react native miniapp (from a JSBundle).
125+
Returns a react native miniapp (from a JSBundle) inside a view.
107126
108127
@param name The name of the mini app, preferably the same name as the jsbundle
109128
without the extension.
110-
@param overlay Boolean determines if view should be rendered as an overlay.
129+
@param overlay determines if view should be rendered as an overlay.
111130
@param properties Any configuration to set up the mini app with.
112131
@return a UIView of the miniapp.
113132
*/
114133
- (UIView *)miniAppViewWithName:(NSString *)name
115134
properties:(NSDictionary *_Nullable)properties
116-
overlay:(BOOL)overlay;
135+
overlay:(BOOL)overlay
136+
__attribute((deprecated("use -miniAppViewWithName:properties:overlay:sizeFlexibility:delegate instead")));
137+
117138

118139
/**
119-
Returns a react native miniapp (from a JSBundle).
140+
Returns a react native miniapp (from a JSBundle) inside a view.
120141
121142
@param name The name of the mini app, that is registered with the AppComponent.
122143
@param properties initialprops for a React Native miniapp.
@@ -126,10 +147,10 @@ without the extension.
126147
- (UIView *)miniAppViewWithName:(NSString *)name
127148
properties:(NSDictionary *_Nullable)properties
128149
sizeFlexibility:(NSInteger)sizeFlexibilty
129-
__attribute((deprecated("use -miniAppViewWithName:properties:sizeFlexibility:delegate instead")));
150+
__attribute((deprecated("use -miniAppViewWithName:properties:overlay:sizeFlexibility:delegate instead")));
130151

131152
/**
132-
Returns a react native miniapp (from a JSBundle).
153+
Returns a react native miniapp (from a JSBundle) inside a view.
133154
134155
@param name The name of the mini app, that is registered with the AppComponent.
135156
@param properties initialprops for a React Native miniapp.
@@ -140,6 +161,23 @@ without the extension.
140161
- (UIView *)miniAppViewWithName:(NSString *)name
141162
properties:(NSDictionary *_Nullable)properties
142163
sizeFlexibility:(NSInteger)sizeFlexibilty
164+
delegate:(id<MiniAppViewDelegate> _Nullable)delegate
165+
__attribute((deprecated("use -miniAppViewWithName:properties:overlay:sizeFlexibility:delegate instead")));
166+
167+
/**
168+
Returns a react native miniapp (from a JSBundle) inside a view.
169+
170+
@param name The name of the mini app, that is registered with the AppComponent.
171+
@param properties initialprops for a React Native miniapp.
172+
@param overlay determines if view should be rendered as an overlay.
173+
@param sizeFlexibilty defines size flexibility type of the root view
174+
@param delegate the object to register as the miniapp's delegate.
175+
@return a UIView of the miniapp.
176+
*/
177+
- (UIView *)miniAppViewWithName:(NSString *)name
178+
properties:(NSDictionary *_Nullable)properties
179+
overlay:(BOOL)overlay
180+
sizeFlexibility:(NSInteger)sizeFlexibility
143181
delegate:(id<MiniAppViewDelegate> _Nullable)delegate;
144182

145183
/**

system-tests/fixtures/ios-container/ElectrodeContainer/ElectrodeReactNative.m

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,27 @@ - (UIViewController *)miniAppWithName:(NSString *)name
163163
properties:(NSDictionary *_Nullable)properties
164164
{
165165
UIViewController *miniAppViewController = [UIViewController new];
166-
miniAppViewController.view = [self miniAppViewWithName:name properties:properties];;
166+
miniAppViewController.view = [self miniAppViewWithName:name properties:properties];
167+
return miniAppViewController;
168+
}
167169

170+
- (UIViewController *)miniAppWithName:(NSString *)name
171+
properties:(NSDictionary *_Nullable)properties
172+
overlay:(BOOL)overlay
173+
sizeFlexibility:(NSInteger)sizeFlexibility
174+
delegate:(id<MiniAppViewDelegate> _Nullable)delegate {
175+
UIViewController *miniAppViewController = [UIViewController new];
176+
miniAppViewController.view = [self miniAppViewWithName:name properties:properties overlay:overlay sizeFlexibility:sizeFlexibility delegate:delegate];
168177
return miniAppViewController;
169178
}
170179

171180
- (UIView *)miniAppViewWithName:(NSString *)name properties:(NSDictionary *_Nullable)properties {
172-
// Use the bridge to generate the view
173181
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge moduleName:name initialProperties:properties];
174182
rootView.backgroundColor = [self rootViewColorWithOverlay:NO];
175183
return rootView;
176184
}
177185

178186
- (UIView *)miniAppViewWithName:(NSString *)name properties:(NSDictionary *_Nullable)properties overlay:(BOOL)overlay {
179-
// Use the bridge to generate the view
180187
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge moduleName:name initialProperties:properties];
181188
rootView.backgroundColor = [self rootViewColorWithOverlay:overlay];
182189
return rootView;
@@ -202,6 +209,19 @@ - (UIView *)miniAppViewWithName:(NSString *)name
202209
return rootView;
203210
}
204211

212+
- (UIView *)miniAppViewWithName:(NSString *)name
213+
properties:(NSDictionary *_Nullable)properties
214+
overlay:(BOOL)overlay
215+
sizeFlexibility:(NSInteger)sizeFlexibility
216+
delegate:(id<MiniAppViewDelegate> _Nullable)delegate {
217+
// Use the bridge to generate the view
218+
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge moduleName:name initialProperties:properties];
219+
rootView.sizeFlexibility = (RCTRootViewSizeFlexibility)sizeFlexibility;
220+
rootView.backgroundColor = [self rootViewColorWithOverlay:overlay];
221+
rootView.delegate = delegate;
222+
return rootView;
223+
}
224+
205225
- (UIColor *)rootViewColorWithOverlay:(BOOL)overlay {
206226
if (overlay) {
207227
return [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:0.5];

0 commit comments

Comments
 (0)