Skip to content

Commit 8f45db3

Browse files
Peter Arganyfacebook-github-bot
authored andcommitted
RCTPicker handwritten view config
Summary: This completes the Picker stack. Use a handwritten view config to avoid calling `requireNativeComponent` in Bridgeless mode. Differential Revision: D23663596 fbshipit-source-id: 5d0811014fd6f66956803a1db5fee8fd1119d5bc
1 parent 3113e47 commit 8f45db3

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

Libraries/Components/Picker/RCTPickerNativeComponent.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
'use strict';
1212

1313
const requireNativeComponent = require('../../ReactNative/requireNativeComponent');
14+
const ReactNativeViewConfigRegistry = require('../../Renderer/shims/ReactNativeViewConfigRegistry');
1415

1516
import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
1617
import type {SyntheticEvent} from '../../Types/CoreEventTypes';
1718
import type {TextStyleProp} from '../../StyleSheet/StyleSheet';
1819
import type {ProcessedColorValue} from '../../StyleSheet/processColor';
1920
import codegenNativeCommands from '../../Utilities/codegenNativeCommands';
21+
import RCTPickerViewConfig from './RCTPickerViewConfig';
2022
import * as React from 'react';
2123

2224
type PickerIOSChangeEvent = SyntheticEvent<
@@ -56,8 +58,15 @@ export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
5658
supportedCommands: ['setNativeSelectedIndex'],
5759
});
5860

59-
const RCTPickerNativeComponent: ComponentType = requireNativeComponent<NativeProps>(
60-
'RCTPicker',
61-
);
61+
let RCTPickerNativeComponent;
62+
if (global.RN$Bridgeless) {
63+
ReactNativeViewConfigRegistry.register('RCTPicker', () => {
64+
return RCTPickerViewConfig;
65+
});
66+
RCTPickerNativeComponent = 'RCTPicker';
67+
} else {
68+
RCTPickerNativeComponent = requireNativeComponent<NativeProps>('RCTPicker');
69+
}
6270

63-
export default RCTPickerNativeComponent;
71+
// flowlint-next-line unclear-type:off
72+
export default ((RCTPickerNativeComponent: any): HostComponent<NativeProps>);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
'use strict';
12+
13+
import ReactNativeViewViewConfig from '../../Components/View/ReactNativeViewViewConfig';
14+
import type {ReactNativeBaseComponentViewConfig} from '../../Renderer/shims/ReactNativeTypes';
15+
16+
const RCTPickerViewConfig = {
17+
uiViewClassName: 'RCTPicker',
18+
bubblingEventTypes: {
19+
topChange: {
20+
phasedRegistrationNames: {
21+
bubbled: 'onChange',
22+
captured: 'onChangeCapture',
23+
},
24+
},
25+
},
26+
directEventTypes: {},
27+
validAttributes: {
28+
...ReactNativeViewViewConfig.validAttributes,
29+
color: {process: require('../../StyleSheet/processColor')},
30+
fontFamily: true,
31+
fontSize: true,
32+
fontStyle: true,
33+
fontWeight: true,
34+
items: true,
35+
onChange: true,
36+
selectedIndex: true,
37+
textAlign: true,
38+
},
39+
};
40+
41+
module.exports = (RCTPickerViewConfig: ReactNativeBaseComponentViewConfig<>);

0 commit comments

Comments
 (0)