Skip to content

Commit

Permalink
RCTPicker handwritten view config
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Peter Argany authored and facebook-github-bot committed Oct 13, 2020
1 parent 3113e47 commit 8f45db3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Libraries/Components/Picker/RCTPickerNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
'use strict';

const requireNativeComponent = require('../../ReactNative/requireNativeComponent');
const ReactNativeViewConfigRegistry = require('../../Renderer/shims/ReactNativeViewConfigRegistry');

import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
import type {SyntheticEvent} from '../../Types/CoreEventTypes';
import type {TextStyleProp} from '../../StyleSheet/StyleSheet';
import type {ProcessedColorValue} from '../../StyleSheet/processColor';
import codegenNativeCommands from '../../Utilities/codegenNativeCommands';
import RCTPickerViewConfig from './RCTPickerViewConfig';
import * as React from 'react';

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

const RCTPickerNativeComponent: ComponentType = requireNativeComponent<NativeProps>(
'RCTPicker',
);
let RCTPickerNativeComponent;
if (global.RN$Bridgeless) {
ReactNativeViewConfigRegistry.register('RCTPicker', () => {
return RCTPickerViewConfig;
});
RCTPickerNativeComponent = 'RCTPicker';
} else {
RCTPickerNativeComponent = requireNativeComponent<NativeProps>('RCTPicker');
}

export default RCTPickerNativeComponent;
// flowlint-next-line unclear-type:off
export default ((RCTPickerNativeComponent: any): HostComponent<NativeProps>);
41 changes: 41 additions & 0 deletions Libraries/Components/Picker/RCTPickerViewConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/

'use strict';

import ReactNativeViewViewConfig from '../../Components/View/ReactNativeViewViewConfig';
import type {ReactNativeBaseComponentViewConfig} from '../../Renderer/shims/ReactNativeTypes';

const RCTPickerViewConfig = {
uiViewClassName: 'RCTPicker',
bubblingEventTypes: {
topChange: {
phasedRegistrationNames: {
bubbled: 'onChange',
captured: 'onChangeCapture',
},
},
},
directEventTypes: {},
validAttributes: {
...ReactNativeViewViewConfig.validAttributes,
color: {process: require('../../StyleSheet/processColor')},
fontFamily: true,
fontSize: true,
fontStyle: true,
fontWeight: true,
items: true,
onChange: true,
selectedIndex: true,
textAlign: true,
},
};

module.exports = (RCTPickerViewConfig: ReactNativeBaseComponentViewConfig<>);

0 comments on commit 8f45db3

Please sign in to comment.