Skip to content

Unify some code in the native picker dialog implementation #1368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions demo/src/screens/componentScreens/PickerScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,6 @@ export default class PickerScreen extends Component {
// );
// }}
// topBarProps={{doneLabel: 'YES', cancelLabel: 'NO'}}
wheelPickerProps={{
style: {width: 200},
color: Colors.green30,
labelStyle: {fontSize: 32, fontFamily: 'sans-serif-condensed-light'},
itemHeight: 55
}}
selectLabelStyle={{color: Colors.green30}}
cancelLabelStyle={{color: Colors.green30}}
>
{_.map(options, option => (
<Picker.Item key={option.value} value={option.value} label={option.label} disabled={option.disabled}/>
Expand All @@ -162,7 +154,13 @@ export default class PickerScreen extends Component {
renderCustomModal={this.renderDialog}
>
{_.map(options, option => (
<Picker.Item key={option.value} value={option} label={option.label} labelStyle={Typography.text65} disabled={option.disabled}/>
<Picker.Item
key={option.value}
value={option}
label={option.label}
labelStyle={Typography.text65}
disabled={option.disabled}
/>
))}
</Picker>

Expand Down Expand Up @@ -236,7 +234,9 @@ export default class PickerScreen extends Component {
))}
</Picker>

<Text text60 marginT-s5 marginB-s2>Migrated Picker</Text>
<Text text60 marginT-s5 marginB-s2>
Migrated Picker
</Text>

<Picker
migrate
Expand Down
34 changes: 27 additions & 7 deletions src/components/picker/NativePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TextField from '../textField';
import PickerDialog from './PickerDialog';
import TouchableOpacity from '../touchableOpacity';
import {Colors} from '../../style';
import {WheelPicker} from '../../nativeComponents';
import {WheelPicker} from '../../incubator';

class NativePicker extends BaseComponent {
static displayName = 'IGNORE';
Expand Down Expand Up @@ -62,21 +62,40 @@ class NativePicker extends BaseComponent {
this.setState({showDialog});
};

renderPicker = () => {
const {selectedValue} = this.state;
const {children, renderNativePicker, pickerStyle, wheelPickerProps, testID} = this.props;
if (_.isFunction(renderNativePicker)) {
return renderNativePicker(this.props);
}
return (
<WheelPicker
style={pickerStyle}
selectedValue={selectedValue}
onChange={this.onValueChange}
testID={`${testID}.wheelPicker`}
{...wheelPickerProps}
>
{children}
</WheelPicker>
);
};

renderPickerDialog = () => {
const {selectedValue, showDialog} = this.state;
const {showDialog} = this.state;

return (
<PickerDialog
height={this.PICKER_HEIGHT + this.MENU_HEIGHT}
{...this.getThemeProps()}
visible={showDialog}
panDirection={null}
onDismiss={this.onCancel}
onValueChange={this.onValueChange}
selectedValue={selectedValue}
onDone={this.onDone}
onCancel={this.onCancel}
/>
>
{this.renderPicker()}
</PickerDialog>
);
};

Expand Down Expand Up @@ -110,5 +129,6 @@ class NativePicker extends BaseComponent {
}
}

NativePicker.Item = WheelPicker.Item;
// TODO: Doesn't seem to be needed
// NativePicker.Item = WheelPicker.Item;
export default NativePicker;
20 changes: 1 addition & 19 deletions src/components/picker/PickerDialog.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,13 @@ import Dialog from '../dialog';
import View from '../view';
import Text from '../text';
import {Colors, BorderRadiuses} from '../../style';
import {WheelPicker} from '../../incubator';

class PickerDialog extends BaseComponent {
static displayName = 'IGNORE';
static propTypes = {
selectedValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
onValueChange: PropTypes.func,
onDone: PropTypes.func,
onCancel: PropTypes.func,
children: PropTypes.array,
/**
* Pass props for the WheelPicker (Android only)
*/
wheelPickerProps: PropTypes.shape(WheelPicker.propTypes),
/**
* select label style
*/
Expand Down Expand Up @@ -68,17 +61,6 @@ class PickerDialog extends BaseComponent {
);
}

renderPicker() {
const {children, onValueChange, selectedValue, renderNativePicker, wheelPickerProps, testID} = this.props;
if (_.isFunction(renderNativePicker)) {
return renderNativePicker(this.props);
}
return (
<WheelPicker selectedValue={selectedValue} onChange={onValueChange} {...wheelPickerProps} testID={`${testID}.wheelPicker`}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the selectedValue, onValueChange, and wheelPickerProps in the propTypes anymore :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed

{children}
</WheelPicker>
);
}

render() {
const dialogProps = extractComponentProps(Dialog, this.props);
Expand All @@ -89,7 +71,7 @@ class PickerDialog extends BaseComponent {
<View style={styles.dialog}>
{this.renderHeader()}
<View flex center paddingH-24>
{this.renderPicker()}
{this.props.children}
</View>
{this.renderFooter()}
</View>
Expand Down
16 changes: 1 addition & 15 deletions src/components/picker/PickerDialog.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import Dialog from '../dialog';
import View from '../view';
import Text from '../text';
import {Colors} from '../../style';
import {WheelPicker} from '../../incubator';

class PickerDialog extends BaseComponent {
static displayName = 'IGNORE';
static propTypes = {
selectedValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
onValueChange: PropTypes.func,
onDone: PropTypes.func,
onCancel: PropTypes.func,
topBarProps: PropTypes.object,
Expand All @@ -39,17 +36,6 @@ class PickerDialog extends BaseComponent {
);
}

renderPicker() {
const {children, onValueChange, selectedValue, renderNativePicker, pickerStyle, testID} = this.props;
if (_.isFunction(renderNativePicker)) {
return renderNativePicker(this.props);
}
return (
<WheelPicker style={pickerStyle} selectedValue={selectedValue} onChange={onValueChange} testID={`${testID}.wheelPicker`}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, you don't need the selectedValue and onValueChange props

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

{children}
</WheelPicker>
);
}

render() {
const dialogProps = extractComponentProps(Dialog, this.props);
Expand All @@ -60,7 +46,7 @@ class PickerDialog extends BaseComponent {
<View flex bg-white>
{this.renderHeader()}
<View centerV flex>
{this.renderPicker()}
{this.props.children}
</View>
<View useSafeArea/>
</View>
Expand Down