Skip to content

Change how we extract a component props #951

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
Sep 23, 2020
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
14 changes: 14 additions & 0 deletions src/commons/modifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ export function extractModifierProps(props: Dictionary<any>) {
return modifierProps;
}

/**
* TODO:
* @deprecated switch to Modifiers#extractComponentProps
*/
export function extractOwnProps(props: Dictionary<any>, ignoreProps: string[]) {
//@ts-ignore
const ownPropTypes = this.propTypes;
Expand All @@ -315,6 +319,16 @@ export function extractOwnProps(props: Dictionary<any>, ignoreProps: string[]) {
return ownProps;
}

export function extractComponentProps(component: any, props: Dictionary<any>, ignoreProps: string[]) {
const componentPropTypes = component.propTypes;
const componentProps = _.chain(props)
.pickBy((_value, key) => _.includes(Object.keys(componentPropTypes), key))
.omit(ignoreProps)
.value();

return componentProps;
}

//@ts-ignore
export function getThemeProps(props = this.props, context = this.context) {
//@ts-ignore
Expand Down
3 changes: 2 additions & 1 deletion src/components/picker/PickerDialog.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import _ from 'lodash';

import {BaseComponent} from '../../commons';
import {extractComponentProps} from '../../commons/modifiers';
import Dialog from '../dialog';
import View from '../view';
import Text from '../text';
Expand Down Expand Up @@ -80,7 +81,7 @@ class PickerDialog extends BaseComponent {
}

render() {
const dialogProps = Dialog.extractOwnProps(this.props);
const dialogProps = extractComponentProps(Dialog, this.props);
return (
<Dialog {...dialogProps} migrate height="50%" width="77%">
<View style={styles.dialog}>
Expand Down
3 changes: 2 additions & 1 deletion src/components/picker/PickerDialog.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import _ from 'lodash';

import {BaseComponent} from '../../commons';
import {extractComponentProps} from '../../commons/modifiers';
import Dialog from '../dialog';
import View from '../view';
import Text from '../text';
Expand Down Expand Up @@ -51,7 +52,7 @@ class PickerDialog extends BaseComponent {
}

render() {
const dialogProps = Dialog.extractOwnProps(this.props);
const dialogProps = extractComponentProps(Dialog, this.props);
return (
<Dialog {...dialogProps} height={250} width="100%" migrate bottom animationConfig={{duration: 300}}>
<View flex bg-white>
Expand Down