Skip to content

Commit dd50412

Browse files
committed
feat: expose controller child views to UIKit hosts
1 parent 8783b49 commit dd50412

4 files changed

Lines changed: 7 additions & 1 deletion

File tree

packages/react-native/plugin/babel-plugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const UIKIT_DEFINITION_CALLEES = new Set([
77
const UIKIT_WORKLET_CALLBACKS = new Set([
88
'create',
99
'createController',
10+
'childrenView',
1011
'dispose',
1112
'mounted',
1213
'update',

packages/react-native/src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export type UIViewControllerDefinition<
217217
createController: (
218218
ctx: UIKitViewContext<Props & ViewProps> & Readonly<Props & ViewProps>,
219219
) => Controller;
220+
childrenView?: (controller: Controller) => unknown;
220221
};
221222

222223
export function init(metadataPath?: string, options?: InstallOptions): boolean;

packages/react-native/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export type UIViewControllerDefinition<
184184
'create'
185185
> & {
186186
createController: (ctx: UIKitCreateArgument<Props & ViewProps>) => Controller;
187+
childrenView?: (controller: Controller) => unknown;
187188
};
188189

189190
const nativeApiGlobalName = '__nativeScriptNativeApi';
@@ -2456,6 +2457,7 @@ export function defineUIViewController<
24562457
return {
24572458
hostView: controllerRecord.view,
24582459
lifecycleValue: controller,
2460+
childrenView: definition.childrenView?.(controller),
24592461
controller,
24602462
};
24612463
},

packages/react-native/test/babel-plugin.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ NativeScript.defineUIViewController({
2929
createController() {
3030
return UIViewController.new();
3131
},
32+
childrenView: (controller) => controller.view,
3233
mounted(controller) {
3334
controller.view.setNeedsLayout();
3435
},
@@ -44,9 +45,10 @@ defineUIKitContainer({
4445

4546
const output = transform(source);
4647
const workletDirectiveCount = (output.match(/"worklet";/g) || []).length;
47-
assert.strictEqual(workletDirectiveCount, 6);
48+
assert.strictEqual(workletDirectiveCount, 7);
4849
assert(output.includes('create() {\n "worklet";'));
4950
assert(output.includes('update: view => {\n "worklet";'));
5051
assert(output.includes('createController() {\n "worklet";'));
52+
assert(output.includes('childrenView: controller => {\n "worklet";'));
5153

5254
console.log('babel plugin tests passed');

0 commit comments

Comments
 (0)