Skip to content
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

add scroll container option to ActionSheet component #3462

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 12 additions & 8 deletions demo/src/screens/componentScreens/ActionSheetScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _ from 'lodash';
import React, {Component} from 'react';
import {View, Text, Button, ActionSheet} from 'react-native-ui-lib'; //eslint-disable-line
import _ from 'lodash';
import {renderBooleanOption} from '../ExampleScreenPresenter';

const useCases = [
{label: 'Default (Android/iOS)', useNativeIOS: false, icons: false},
Expand All @@ -11,13 +12,13 @@ const collectionsIcon = require('../../assets/icons/collections.png');
const starIcon = require('../../assets/icons/star.png');
const shareIcon = require('../../assets/icons/share.png');


export default class ActionSheetScreen extends Component {
state = {
showNative: false,
showCustom: false,
showCustomIcons: false,
pickedOption: undefined
pickedOption: undefined,
scrollContainer: false
};

pickOption(index: string) {
Expand All @@ -27,7 +28,7 @@ export default class ActionSheetScreen extends Component {
}

render() {
const {showCustom, showCustomIcons, showNative, pickedOption} = this.state;
const {showCustom, showCustomIcons, showNative, pickedOption, scrollContainer} = this.state;
return (
<View flex padding-25>
<Text text30>Action Sheet</Text>
Expand All @@ -47,7 +48,8 @@ export default class ActionSheetScreen extends Component {
showNative: useCase.useNativeIOS,
showCustom: !useCase.useNativeIOS && !useCase.icons,
showCustomIcons: !useCase.useNativeIOS && useCase.icons
})}
})
}
/>
);
})}
Expand All @@ -57,14 +59,14 @@ export default class ActionSheetScreen extends Component {
<Text>User picked {pickedOption}</Text>
</View>
)}

<ActionSheet
title={'Title'}
message={'Message of action sheet'}
cancelButtonIndex={3}
destructiveButtonIndex={0}
useNativeIOS={false}
migrateDialog
scrollContainer={scrollContainer}
options={[
{label: 'option 1', onPress: () => this.pickOption('option 1')},
{label: 'option 2', onPress: () => this.pickOption('option 2')},
Expand All @@ -74,13 +76,13 @@ export default class ActionSheetScreen extends Component {
visible={showCustom}
onDismiss={() => this.setState({showCustom: false})}
/>

<ActionSheet
title={'Title'}
message={'Message of action sheet'}
cancelButtonIndex={3}
destructiveButtonIndex={0}
migrateDialog
scrollContainer={scrollContainer}
options={[
{label: 'option 1', onPress: () => this.pickOption('option 1'), iconSource: collectionsIcon},
{label: 'option 2', onPress: () => this.pickOption('option 2'), iconSource: shareIcon},
Expand All @@ -91,7 +93,6 @@ export default class ActionSheetScreen extends Component {
visible={showCustomIcons}
onDismiss={() => this.setState({showCustomIcons: false})}
/>

<ActionSheet
title={'Title'}
message={'Message of action sheet'}
Expand All @@ -107,6 +108,9 @@ export default class ActionSheetScreen extends Component {
useNativeIOS
onDismiss={() => this.setState({showNative: false})}
/>
<View marginT-s2>
{renderBooleanOption.call(this, 'Use ScrollView (default ActionSheet):', 'scrollContainer')}
</View>
</View>
);
}
Expand Down
26 changes: 20 additions & 6 deletions src/components/actionSheet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import _ from 'lodash';
import React, {Component} from 'react';
import {ActionSheetIOS, StyleSheet, StyleProp, ViewStyle, ImageProps, ImageSourcePropType} from 'react-native';
import {
ActionSheetIOS,
StyleSheet,
StyleProp,
ViewStyle,
ImageProps,
ImageSourcePropType,
ScrollView
} from 'react-native';
import {Colors} from '../../style';
import {asBaseComponent, Constants} from '../../commons/new';
import Dialog, {DialogProps} from '../dialog';
Expand Down Expand Up @@ -73,7 +81,7 @@ type ActionSheetProps = {
*/
optionsStyle?: StyleProp<ViewStyle>;
/**
* Render custom title
* Render custom title, relevant for old Dialog only
*/
renderTitle?: () => JSX.Element;
/**
Expand Down Expand Up @@ -101,6 +109,10 @@ type ActionSheetProps = {
* testID for e2e tests
*/
testID?: string;
/**
* Whether to use ScrollView as the container
*/
scrollContainer?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming convention in this case is more like 'useScrollView' or 'useScrollContainer' since it's a boolean and not element.
But anyways I wonder if we should add this prop at all or figure out in the component when the children height is greater then the container's and use the scrollview instead of a view.

};

/**
Expand Down Expand Up @@ -211,12 +223,13 @@ class ActionSheet extends Component<ActionSheetProps> {

renderSheet() {
const {renderTitle} = this.props;
const {containerStyle} = this.props;
const {containerStyle, migrateDialog, scrollContainer = false} = this.props;
const Container = scrollContainer ? ScrollView : View;
return (
<View style={[styles.sheet, containerStyle]}>
{_.isFunction(renderTitle) ? renderTitle() : this.renderTitle()}
<Container style={[styles.sheet, containerStyle]}>
{_.isFunction(renderTitle) ? renderTitle() : !migrateDialog && this.renderTitle()}
{this.renderActions()}
</View>
</Container>
);
}

Expand Down Expand Up @@ -266,6 +279,7 @@ class ActionSheet extends Component<ActionSheetProps> {
containerStyle={[styles.incubatorDialog, dialogStyle]}
visible={visible}
onDismiss={onDismiss}
headerProps={{title: this.props.title}}
>
{this.renderSheet()}
</IncubatorDialog>
Expand Down