Skip to content

Infra/picker expandable overlay #1632

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 10 commits into from
Nov 14, 2021
4 changes: 2 additions & 2 deletions demo/src/screens/componentScreens/PickerScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default class PickerScreen extends Component {
onChange={filter => this.setState({filter})}
renderPicker={({label}) => {
return (
<View row center>
<View row>
<Image style={{marginRight: 1, height: 16, resizeMode: 'contain'}} source={tagIcon}/>
<Text grey10 text80>
{label} Posts
Expand All @@ -194,7 +194,7 @@ export default class PickerScreen extends Component {
getItemValue={contact => contact.name}
renderPicker={contact => {
return (
<View row center>
<View row>
<Avatar size={30} source={{uri: contact.thumbnail}}/>
<Text text70 marginL-10>
{contact.name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ export default class TextFieldScreen extends Component {
</Text>
<Incubator.ExpandableOverlay
ref={this.expandableInputRef}
modalProps={{animationType: 'slide'}}
modalProps={{animationType: 'slide', onDismiss: () => console.warn('Modal is dismissed')}}
expandableContent={this.renderInputModal()}
showTopBar
topBarProps={{title: 'Edit Input', doneLabel: 'Done', onCancel: this.onCancel, onDone: this.onDone}}
dialogProps={{bottom: true}}
>
<Incubator.TextField placeholder="Expandable input" value={textFieldValue}/>
</Incubator.ExpandableOverlay>
Expand All @@ -112,7 +111,7 @@ export default class TextFieldScreen extends Component {
ref={this.expandablePickerRef}
useDialog
expandableContent={this.renderPickerContent()}
dialogProps={{bottom: true}}
dialogProps={{bottom: true, onDismiss: () => console.warn('Dialog is dismissed')}}
>
{this.renderColorRow(selectedColor)}
</Incubator.ExpandableOverlay>
Expand Down
14 changes: 14 additions & 0 deletions generatedTypes/src/incubator/expandableOverlay/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import React, { PropsWithChildren } from 'react';
import { TouchableOpacityProps } from '../../components/touchableOpacity';
import { ModalProps, ModalTopBarProps } from '../../components/modal';
import { DialogProps } from '../../components/dialog';
export interface RenderCustomOverlayProps {
visible: boolean;
openExpandable: () => void;
closeExpandable: () => void;
toggleExpandable: () => void;
}
export declare type ExpandableOverlayProps = TouchableOpacityProps & PropsWithChildren<{
/**
* The content to render inside the expandable modal/dialog
Expand All @@ -27,6 +33,10 @@ export declare type ExpandableOverlayProps = TouchableOpacityProps & PropsWithCh
* The modal top bar props to pass on
*/
topBarProps?: ModalTopBarProps;
/**
* A custom overlay to render instead of Modal or Dialog components
*/
renderCustomOverlay?: (props: RenderCustomOverlayProps) => React.ReactElement | undefined;
}>;
interface ExpandableOverlayMethods {
openExpandable: () => void;
Expand Down Expand Up @@ -57,6 +67,10 @@ declare const _default: React.ForwardRefExoticComponent<TouchableOpacityProps &
* The modal top bar props to pass on
*/
topBarProps?: ModalTopBarProps | undefined;
/**
* A custom overlay to render instead of Modal or Dialog components
*/
renderCustomOverlay?: ((props: RenderCustomOverlayProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined) | undefined;
} & {
children?: React.ReactNode;
} & React.RefAttributes<ExpandableOverlayMethods>>;
Expand Down
28 changes: 16 additions & 12 deletions src/components/picker/PickerModal.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// TODO: This should be renamed to PickerOverlayContent cause it's
// not responsible for rendering the Modal anymore
import _ from 'lodash';
import PropTypes from 'prop-types';
import React from 'react';
import {StyleSheet, FlatList, TextInput} from 'react-native';
import {Constants} from '../../helpers';
// import {Constants} from '../../helpers';
import {Typography, Colors} from '../../style';
import Assets from '../../assets';
import {BaseComponent} from '../../commons';
Expand Down Expand Up @@ -80,17 +82,18 @@ class PickerModal extends BaseComponent {
};

render() {
const {visible, enableModalBlur, topBarProps, listProps, children, onShow, pickerModalProps} = this.props;
const {/* visible, enableModalBlur, */topBarProps, listProps, children/* , onShow, pickerModalProps */} = this.props;
return (
<Modal
animationType={'slide'}
transparent={Constants.isIOS && enableModalBlur}
enableModalBlur={Constants.isIOS && enableModalBlur}
visible={visible}
onRequestClose={topBarProps.onCancel}
onShow={onShow}
{...pickerModalProps}
>
<>
{/* <Modal
animationType={'slide'}
transparent={Constants.isIOS && enableModalBlur}
enableModalBlur={Constants.isIOS && enableModalBlur}
visible={visible}
onRequestClose={topBarProps.onCancel}
onShow={onShow}
{...pickerModalProps}
> */}
<Modal.TopBar {...topBarProps}/>
{this.renderSearchInput()}

Expand All @@ -100,7 +103,8 @@ class PickerModal extends BaseComponent {
keyExtractor={this.keyExtractor}
{...listProps}
/>
</Modal>
</>
// </Modal>
);
}
}
Expand Down
12 changes: 0 additions & 12 deletions src/components/picker/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,4 @@ describe('Picker', () => {
expect(uut.getLabelValueText()).toEqual(`${countries[2].label}, ${countries[4].label}`);
});
});

describe('handlePickerOnPress', () => {
it('should get label out of an array of items', () => {
const onPress = jest.fn(() => {});
const uut = new Picker({value: countries[0], onPress});
uut.toggleExpandableModal = jest.fn(uut.toggleExpandableModal);

uut.handlePickerOnPress();
expect(onPress).toHaveBeenCalled();
expect(uut.toggleExpandableModal).toHaveBeenCalled();
});
});
});
Loading