Skip to content

Picker - add support for layout modifiers (margin, paddings) #928

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 9 commits into from
Sep 30, 2020
Merged
54 changes: 26 additions & 28 deletions demo/src/screens/componentScreens/PickerScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,18 @@ export default class PickerScreen extends Component {
))}
</Picker>

<View marginT-20>
<Picker
placeholder="Favorite Languages"
value={this.state.languages}
onChange={items => this.setState({languages: items})}
mode={Picker.modes.MULTI}
rightIconSource={dropdown}
>
{_.map(options, option => (
<Picker.Item key={option.value} value={option} disabled={option.disabled}/>
))}
</Picker>
</View>
<Picker
marginT-20
placeholder="Favorite Languages"
value={this.state.languages}
onChange={items => this.setState({languages: items})}
mode={Picker.modes.MULTI}
rightIconSource={dropdown}
>
{_.map(options, option => (
<Picker.Item key={option.value} value={option} disabled={option.disabled}/>
))}
</Picker>

<Picker
title="Native Picker"
Expand Down Expand Up @@ -156,21 +155,20 @@ export default class PickerScreen extends Component {
))}
</Picker>

<View marginT-20>
<Picker
title="Custom modal"
placeholder="Pick multiple Languages"
value={this.state.customModalValues}
onChange={items => this.setState({customModalValues: items})}
mode={Picker.modes.MULTI}
rightIconSource={dropdown}
renderCustomModal={this.renderDialog}
>
{_.map(options, option => (
<Picker.Item key={option.value} value={option} label={option.label} disabled={option.disabled}/>
))}
</Picker>
</View>
<Picker
marginT-20
title="Custom modal"
placeholder="Pick multiple Languages"
value={this.state.customModalValues}
onChange={items => this.setState({customModalValues: items})}
mode={Picker.modes.MULTI}
rightIconSource={dropdown}
renderCustomModal={this.renderDialog}
>
{_.map(options, option => (
<Picker.Item key={option.value} value={option} label={option.label} disabled={option.disabled}/>
))}
</Picker>

<Text marginT-20 marginB-10 text70 dark60>
Custom Picker:
Expand Down
7 changes: 5 additions & 2 deletions src/components/picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import _ from 'lodash';
import PropTypes from 'prop-types';
import React, {PureComponent} from 'react';
import {asBaseComponent, forwardRef} from '../../commons';
import {extractMarginValues, extractPaddingValues} from '../../commons/modifiers';
import View from '../../components/view';
import Modal from '../modal';
import Button from '../../components/button';
Expand Down Expand Up @@ -364,7 +365,7 @@ class Picker extends PureComponent {
};

render() {
const {useNativePicker, renderPicker, customPickerProps, testID} = this.props;
const {useNativePicker, renderPicker, customPickerProps, containerStyle, testID} = this.props;

if (useNativePicker) {
return <NativePicker {...this.props}/>;
Expand All @@ -385,10 +386,12 @@ class Picker extends PureComponent {

const textInputProps = TextField.extractOwnProps(this.props);
const label = this.getLabelValueText();

const layoutProps = {...extractMarginValues(this.props), ...extractPaddingValues(this.props)};

return (
<TextField
{...textInputProps}
containerStyle={[containerStyle, layoutProps]}
{...this.getAccessibilityInfo()}
importantForAccessibility={'no-hide-descendants'}
value={label}
Expand Down