Skip to content

Commit

Permalink
Fix Picker to use new dialog and also fix height issues (#3331)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanshar authored Oct 29, 2024
1 parent 6647850 commit 59b71f6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
1 change: 0 additions & 1 deletion demo/src/screens/componentScreens/PickerScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export default class PickerScreen extends Component {
<Button link label="Done" onPress={onDone}/>
</View>
)}
customPickerProps={{migrateDialog: true, dialogProps: {bottom: true, width: '100%', height: '45%'}}}
showSearch
searchPlaceholder={'Search a language'}
items={dialogOptions}
Expand Down
1 change: 0 additions & 1 deletion src/components/actionSheet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ class ActionSheet extends Component<ActionSheetProps> {
}

return (
// @ts-expect-error height might be null here
<IncubatorDialog
bottom
centerH
Expand Down
16 changes: 7 additions & 9 deletions src/components/picker/PickerItemsList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import React, {useCallback, useContext, useState, useMemo} from 'react';
import React, {useCallback, useContext, useState} from 'react';
import {StyleSheet, FlatList, TextInput, ListRenderItemInfo, ActivityIndicator} from 'react-native';
import {Typography, Colors} from '../../style';
import Assets from '../../assets';
Expand Down Expand Up @@ -39,13 +39,6 @@ const PickerItemsList = (props: PickerItemsListProps) => {
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};
return style;
}, [/* useDialog */]);

const renderSearchInput = () => {
if (showSearch) {
Expand Down Expand Up @@ -180,7 +173,7 @@ const PickerItemsList = (props: PickerItemsListProps) => {
};

return (
<View style={wrapperContainerStyle} useSafeArea={useSafeArea}>
<View style={styles.container} useSafeArea={useSafeArea}>
{renderPickerHeader()}
{showLoader ? renderLoader() : renderContent()}
</View>
Expand All @@ -189,6 +182,11 @@ const PickerItemsList = (props: PickerItemsListProps) => {

const styles = StyleSheet.create({
modalBody: {},
container: {
minHeight: 250,
flexShrink: 1,
maxHeight: Constants.isWeb ? Constants.windowHeight * 0.75 : undefined
},
searchInputContainer: {
flexDirection: 'row',
alignItems: 'center',
Expand Down
9 changes: 5 additions & 4 deletions src/components/picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import {
PickerItemsListProps,
PickerMethods
} from './types';
import {DialogProps} from '../../incubator/Dialog';

const DIALOG_PROPS = {
const DEFAULT_DIALOG_PROPS: DialogProps = {
bottom: true,
width: '100%',
height: 250
width: '100%'
};

type PickerStatics = {
Expand Down Expand Up @@ -278,7 +278,8 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
<ExpandableOverlay
ref={pickerExpandable}
useDialog={useDialog || useWheelPicker}
dialogProps={DIALOG_PROPS}
dialogProps={DEFAULT_DIALOG_PROPS}
migrateDialog
expandableContent={expandableModalContent}
renderCustomOverlay={renderOverlay ? _renderOverlay : undefined}
onPress={onPress}
Expand Down
2 changes: 1 addition & 1 deletion src/incubator/Dialog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export interface _DialogProps extends AlignmentModifiers, Pick<ViewProps, 'useSa
/**
* The dialog height.
*/
height?: string | number;
height?: string | number | null;

/**
* Callback that is called after the dialog's dismiss (after the animation has ended).
Expand Down
1 change: 0 additions & 1 deletion src/incubator/expandableOverlay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ const ExpandableOverlay = (props: ExpandableOverlayProps, ref: any) => {
const renderDialog = () => {
const Dialog = migrateDialog ? DialogNew : DialogOld;
return (
// @ts-expect-error
<Dialog testID={`${testID}.overlay`} {...dialogProps} visible={visible} onDismiss={closeExpandable}>
{expandableContent}
</Dialog>
Expand Down

0 comments on commit 59b71f6

Please sign in to comment.