-
Notifications
You must be signed in to change notification settings - Fork 734
Feat/picker use dialog 2 #2804
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
Feat/picker use dialog 2 #2804
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e2d9917
Picker support useDialog
adids1221 296b239
Merge branch 'master' into feat/Picker_useDialog
adids1221 eb5b26c
don't render status bar when useDialog passed
adids1221 cd519d7
wrapped the expandableOverly with ts-expect-error
adids1221 88a9a74
Merge branch 'master' into feat/Picker_useDialog
adids1221 7a3fa0a
Merge branch 'master' into feat/Picker_useDialog
adids1221 4bf7d54
PickerItemList flex is defined by useDialog prop
adids1221 401288b
Merge branch 'master' into feat/Picker_useDialog
adids1221 c70b954
flex fixes, ModalTopBar won't show up when useDialog is set to true
adids1221 f164096
fix for web
adids1221 8c3bd0d
Merge branch 'master' into feat/Picker_useDialog
adids1221 60eb6bc
Merge branch 'master' into feat/Picker_useDialog
ethanshar 4c10972
Merge branch 'master' into feat/Picker_useDialog
ethanshar f92b364
Export Picker context and add done button for multi mode + useDialog
ethanshar 7308ad2
Merge branch 'master' into feat/Picker_useDialog_2
ethanshar c9b3d62
Support passing custom render for the picker dialog header
ethanshar 8d75d8d
Merge branch 'master' into feat/Picker_useDialog_2
ethanshar 61c2050
Remove redundant useDialog prop
ethanshar e11af69
Fix issue with FlatList not being flexed correctly inside a dialog
ethanshar 044e19a
Remove redundant line
ethanshar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ const options = [ | |
{label: 'C++', value: 'c++', disabled: true}, | ||
{label: 'Perl', value: 'perl'} | ||
]; | ||
|
||
const filters = [ | ||
{label: 'All', value: 0}, | ||
{label: 'Draft', value: 1}, | ||
|
@@ -45,6 +46,16 @@ const schemes = [ | |
{label: 'Dark', value: 3} | ||
]; | ||
|
||
const dialogOptions = [ | ||
{label: 'Option 1', value: 0}, | ||
{label: 'Option 2', value: 1}, | ||
{label: 'Option 3', value: 2}, | ||
{label: 'Option 4', value: 3, disabled: true}, | ||
{label: 'Option 5', value: 4}, | ||
{label: 'Option 6', value: 5}, | ||
{label: 'Option 7', value: 6}, | ||
{label: 'Option 8', value: 6} | ||
]; | ||
export default class PickerScreen extends Component { | ||
picker = React.createRef<PickerMethods>(); | ||
state = { | ||
|
@@ -53,7 +64,9 @@ export default class PickerScreen extends Component { | |
language: undefined, | ||
language2: options[2].value, | ||
languages: [], | ||
option: undefined, | ||
nativePickerValue: 'java', | ||
dialogPickerValue: 'java', | ||
customModalValues: [], | ||
filter: filters[0].value, | ||
scheme: schemes[0].value, | ||
|
@@ -125,7 +138,6 @@ export default class PickerScreen extends Component { | |
label="Wheel Picker" | ||
placeholder="Pick a Language" | ||
useWheelPicker | ||
// useWheelPicker | ||
value={this.state.nativePickerValue} | ||
onChange={nativePickerValue => this.setState({nativePickerValue})} | ||
trailingAccessory={<Icon source={dropdown}/>} | ||
|
@@ -164,6 +176,30 @@ export default class PickerScreen extends Component { | |
))} | ||
</Picker> | ||
|
||
<Picker | ||
label="Dialog Picker" | ||
placeholder="Favorite Language" | ||
mode={Picker.modes.MULTI} | ||
value={this.state.option} | ||
enableModalBlur={false} | ||
onChange={item => this.setState({option: item})} | ||
topBarProps={{title: 'Languages'}} | ||
useDialog | ||
renderCustomDialogHeader={({onDone, onCancel}) => ( | ||
<View padding-s5 row spread> | ||
<Button link label="Cancel" onPress={onCancel}/> | ||
<Button link label="Done" onPress={onDone}/> | ||
</View> | ||
)} | ||
customPickerProps={{migrateDialog: true, dialogProps: {bottom: true, width: '100%', height: '45%'}}} | ||
showSearch | ||
searchPlaceholder={'Search a language'} | ||
> | ||
{_.map(dialogOptions, option => ( | ||
<Picker.Item key={option.value} value={option.value} label={option.label} disabled={option.disabled}/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last items are not properly scrollable \ visible |
||
))} | ||
</Picker> | ||
|
||
<Text marginB-10 text70 $textDefault> | ||
Custom Picker: | ||
</Text> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||||
import _ from 'lodash'; | ||||||||
import React, {useCallback, useContext, useState} from 'react'; | ||||||||
import React, {useCallback, useContext, useState, useMemo} from 'react'; | ||||||||
import {StyleSheet, FlatList, TextInput, ListRenderItemInfo} from 'react-native'; | ||||||||
import {Typography, Colors} from '../../style'; | ||||||||
import Assets from '../../assets'; | ||||||||
|
@@ -9,9 +9,10 @@ import Text from '../text'; | |||||||
import Icon from '../icon'; | ||||||||
import Button from '../button'; | ||||||||
import WheelPicker from '../WheelPicker'; | ||||||||
import {PickerItemProps, PickerItemsListProps, PickerSingleValue} from './types'; | ||||||||
import {PickerItemProps, PickerItemsListProps, PickerSingleValue, PickerModes} from './types'; | ||||||||
import PickerContext from './PickerContext'; | ||||||||
import PickerItem from './PickerItem'; | ||||||||
import {Constants} from '../../commons/new'; | ||||||||
|
||||||||
const keyExtractor = (_item: string, index: number) => index.toString(); | ||||||||
|
||||||||
|
@@ -27,11 +28,21 @@ const PickerItemsList = (props: PickerItemsListProps) => { | |||||||
searchPlaceholder = 'Search...', | ||||||||
onSearchChange, | ||||||||
renderCustomSearch, | ||||||||
renderCustomDialogHeader, | ||||||||
useSafeArea, | ||||||||
useDialog, | ||||||||
mode, | ||||||||
testID | ||||||||
} = props; | ||||||||
const context = useContext(PickerContext); | ||||||||
const [wheelPickerValue, setWheelPickerValue] = useState<PickerSingleValue>(context.value ?? items?.[0].value); | ||||||||
// TODO: Might not need this memoized style, instead we can move it to a stylesheet | ||||||||
const wrapperContainerStyle = useMemo(() => { | ||||||||
// const shouldFlex = Constants.isWeb ? 1 : useDialog ? 1 : 1; | ||||||||
const shouldFlex = true; | ||||||||
const style = {flex: shouldFlex ? 1 : 0, maxHeight: Constants.isWeb ? Constants.windowHeight * 0.75 : undefined}; | ||||||||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
return style; | ||||||||
}, [/* useDialog */]); | ||||||||
|
||||||||
const renderSearchInput = () => { | ||||||||
if (showSearch) { | ||||||||
|
@@ -135,11 +146,19 @@ const PickerItemsList = (props: PickerItemsListProps) => { | |||||||
); | ||||||||
}; | ||||||||
|
||||||||
const renderPickerHeader = () => { | ||||||||
if (renderCustomDialogHeader) { | ||||||||
return renderCustomDialogHeader?.({onDone: topBarProps?.onDone, onCancel: topBarProps?.onCancel}); | ||||||||
} else if (!useDialog || mode === PickerModes.MULTI) { | ||||||||
return <Modal.TopBar {...topBarProps}/>; | ||||||||
} | ||||||||
}; | ||||||||
|
||||||||
return ( | ||||||||
<View bg-$backgroundDefault flex useSafeArea={useSafeArea}> | ||||||||
<View bg-$backgroundDefault style={wrapperContainerStyle} useSafeArea={useSafeArea}> | ||||||||
{!useWheelPicker && ( | ||||||||
<> | ||||||||
{<Modal.TopBar {...topBarProps}/>} | ||||||||
{renderPickerHeader()} | ||||||||
{renderSearchInput()} | ||||||||
{renderList()} | ||||||||
</> | ||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it's related to the PR, but passing
useSafeArea
does not work together withuseDialog
customPickerProps.dialogProps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the flexness issue of the FlatList inside the dialog