From 852b5758ef9fbb858ca298ef23f7692369dc2e17 Mon Sep 17 00:00:00 2001 From: Lucas Raposeiras Date: Fri, 10 Sep 2021 00:35:34 -0300 Subject: [PATCH] Add prop for rendering a header above the list --- README.md | 1 + SampleApp/App.tsx | 23 +++++++++++++++++++++++ index.d.ts | 5 +++++ index.js | 4 ++++ 4 files changed, 33 insertions(+) diff --git a/README.md b/README.md index c7ade77..5396663 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,7 @@ Prop | Type | Optional | Default | Description `enableShortPress` | bool | Yes | true | enables short press. This is regular touch behavior. `enableLongPress` | bool | Yes | false | enables long press. When true, `onModalOpen` returns `{longPress: true}` `optionsTestIDPrefix` | string | Yes | `'default'` | This prefixes each selectable option's testID prop if no testID keys are provided in `props.data` array objects. Default for each option's testID: 'default-\' +`header` | node | Yes | undefined | Render a header above the list ### Methods diff --git a/SampleApp/App.tsx b/SampleApp/App.tsx index 4833995..4fe8520 100644 --- a/SampleApp/App.tsx +++ b/SampleApp/App.tsx @@ -129,6 +129,29 @@ export const SampleApp = () => { }} componentExtractor={(option) => } /> + + {/* With a fixed header at the top of the list */} + x.name} + labelExtractor={(x) => x.name} + initValue="listType without FlatList" + initValueTextStyle={{ color: "black" }} + selectStyle={{ borderColor: "black" }} + selectTextStyle={{ color: "blue" }} + onChange={(option) => { + setTextInputValue(option.name); + }} + componentExtractor={(option) => } + header={ + + What country would you pick? + + Please, select an option + + + } + /> ); }; diff --git a/index.d.ts b/index.d.ts index 0fb895e..07886ff 100644 --- a/index.d.ts +++ b/index.d.ts @@ -367,6 +367,11 @@ interface IModalSelectorProps { * Default for each option's testID: 'default-' */ optionsTestIDPrefix?: string; + + /** + * Render a header above the list + */ + header?: React.ReactNode; } diff --git a/index.js b/index.js index a7ece24..f6916c1 100644 --- a/index.js +++ b/index.js @@ -76,6 +76,7 @@ const propTypes = { enableShortPress: PropTypes.bool, enableLongPress: PropTypes.bool, optionsTestIDPrefix: PropTypes.string, + header: PropTypes.node, }; const defaultProps = { @@ -130,6 +131,7 @@ const defaultProps = { enableShortPress: true, enableLongPress: false, optionsTestIDPrefix: 'default', + header: undefined, }; export default class ModalSelector extends React.Component { @@ -278,6 +280,7 @@ export default class ModalSelector extends React.Component { cancelStyle, cancelTextStyle, cancelText, + header, } = this.props; let options = data.map((item, index) => { @@ -310,6 +313,7 @@ export default class ModalSelector extends React.Component { + {header} {listType === 'FLATLIST'?