fix actionsheet for tablets

This commit is contained in:
ammarahm-ed
2020-01-24 18:48:33 +05:00
parent 73920ff802
commit 52b9d24118
3 changed files with 95 additions and 40 deletions

View File

@@ -1,15 +1,15 @@
import PropTypes from 'prop-types';
import React, {Component} from 'react'; import React, {Component} from 'react';
import { import {
Animated,
Dimensions,
KeyboardAvoidingView,
Modal,
Platform,
ScrollView,
TouchableOpacity,
View, View,
TouchableOpacity,
Dimensions,
ScrollView,
Modal,
KeyboardAvoidingView,
Platform,
Animated,
} from 'react-native'; } from 'react-native';
import PropTypes from 'prop-types';
import {styles} from './styles'; import {styles} from './styles';
const deviceHeight = Dimensions.get('window').height; const deviceHeight = Dimensions.get('window').height;
@@ -99,8 +99,9 @@ export default class ActionSheet extends Component {
initialOffsetFromBottom, initialOffsetFromBottom,
bounceOnOpen, bounceOnOpen,
animated, animated,
defaultOverlayOpacity, footerHeight,
openAnimationDuration, footerAlwaysVisible,
extraScroll,
} = this.props; } = this.props;
let addFactor = deviceHeight * 0.1; let addFactor = deviceHeight * 0.1;
@@ -119,10 +120,16 @@ export default class ActionSheet extends Component {
} }
return; return;
} else { } else {
this.customComponentHeight = height - 100; if (footerAlwaysVisible) {
this.customComponentHeight = height;
} else {
this.customComponentHeight = height - footerHeight;
}
let scrollOffset = gestureEnabled let scrollOffset = gestureEnabled
? this.customComponentHeight * initialOffsetFromBottom + addFactor ? this.customComponentHeight * initialOffsetFromBottom +
: this.customComponentHeight + addFactor; addFactor +
extraScroll
: this.customComponentHeight + addFactor + extraScroll;
this.scrollViewRef.scrollTo({ this.scrollViewRef.scrollTo({
x: 0, x: 0,
@@ -158,7 +165,7 @@ export default class ActionSheet extends Component {
if (this.prevScroll < verticalOffset) { if (this.prevScroll < verticalOffset) {
if (verticalOffset - this.prevScroll > springOffset * 0.75) { if (verticalOffset - this.prevScroll > springOffset * 0.75) {
let addFactor = deviceHeight * 0.1; let addFactor = deviceHeight * 0.1;
this._scrollTo(this.customComponentHeight + addFactor); this._scrollTo(this.customComponentHeight + addFactor + extraScroll);
} else { } else {
this._scrollTo(this.prevScroll); this._scrollTo(this.prevScroll);
} }
@@ -213,7 +220,12 @@ export default class ActionSheet extends Component {
indicatorColor, indicatorColor,
defaultOverlayOpacity, defaultOverlayOpacity,
children, children,
customStyles, containerStyle,
footerStyle,
footerHeight,
CustomHeaderComponent,
CustomFooterComponent,
headerAlwaysVisible,
} = this.props; } = this.props;
return ( return (
@@ -277,7 +289,7 @@ export default class ActionSheet extends Component {
onLayout={this._showModal} onLayout={this._showModal}
style={[ style={[
styles.container, styles.container,
customStyles, containerStyle,
{ {
...getElevation(elevation), ...getElevation(elevation),
zIndex: 11, zIndex: 11,
@@ -288,26 +300,33 @@ export default class ActionSheet extends Component {
], ],
}, },
]}> ]}>
{gestureEnabled ? ( {gestureEnabled || headerAlwaysVisible ? (
CustomHeaderComponent ? (
CustomHeaderComponent
) : (
<View <View
style={[ style={[
styles.indicator, styles.indicator,
{backgroundColor: indicatorColor}, {backgroundColor: indicatorColor},
]} ]}
/> />
)
) : null} ) : null}
{children} {children}
<View <View
style={[ style={[
{ {
height: 100,
width: '100%', width: '100%',
backgroundColor: 'white', backgroundColor: 'white',
}, },
customStyles, footerStyle,
]} {
/> height: footerHeight,
},
]}>
{CustomFooterComponent}
</View>
</Animated.View> </Animated.View>
</ScrollView> </ScrollView>
</KeyboardAvoidingView> </KeyboardAvoidingView>
@@ -319,18 +338,25 @@ export default class ActionSheet extends Component {
ActionSheet.defaultProps = { ActionSheet.defaultProps = {
children: <View />, children: <View />,
CustomFooterComponent: <View />,
CustomHeaderComponent: null,
footerAlwaysVisible: false,
headerAlwaysVisible: false,
containerStyle: {},
footerHeight: 80,
footerStyle: {},
animated: true, animated: true,
closeOnPressBack: true, closeOnPressBack: true,
gestureEnabled: false, gestureEnabled: false,
bounceOnOpen: false, bounceOnOpen: false,
bounciness: 8, bounciness: 8,
extraScroll: 0,
closeAnimationDuration: 300, closeAnimationDuration: 300,
openAnimationDuration: 200, openAnimationDuration: 200,
springOffset: 50, springOffset: 50,
elevation: 5, elevation: 5,
initialOffsetFromBottom: 1, initialOffsetFromBottom: 1,
indicatorColor: 'gray', indicatorColor: 'gray',
customStyles: {},
defaultOverlayOpacity: 0.3, defaultOverlayOpacity: 0.3,
overlayColor: 'black', overlayColor: 'black',
onClose: () => {}, onClose: () => {},
@@ -338,6 +364,14 @@ ActionSheet.defaultProps = {
}; };
ActionSheet.propTypes = { ActionSheet.propTypes = {
children: PropTypes.node, children: PropTypes.node,
CustomHeaderComponent: PropTypes.node,
CustomFooterComponent: PropTypes.node,
extraScroll: PropTypes.number,
footerAlwaysVisible: PropTypes.bool,
headerAlwaysVisible: PropTypes.bool,
containerStyle: PropTypes.object,
footerStyle: PropTypes.object,
footerHeight: PropTypes.number,
animated: PropTypes.bool, animated: PropTypes.bool,
closeOnPressBack: PropTypes.bool, closeOnPressBack: PropTypes.bool,
gestureEnabled: PropTypes.bool, gestureEnabled: PropTypes.bool,
@@ -350,7 +384,6 @@ ActionSheet.propTypes = {
elevation: PropTypes.number, elevation: PropTypes.number,
initialOffsetFromBottom: PropTypes.number, initialOffsetFromBottom: PropTypes.number,
indicatorColor: PropTypes.string, indicatorColor: PropTypes.string,
customStyles: PropTypes.object,
overlayColor: PropTypes.string, overlayColor: PropTypes.string,
onClose: PropTypes.func, onClose: PropTypes.func,
onOpen: PropTypes.func, onOpen: PropTypes.func,

View File

@@ -359,8 +359,8 @@ export const ActionSheetComponent = ({
}}> }}>
<View <View
style={{ style={{
width: DDS.isTab ? (w * 0.6) / 10 : w / 10, width: DDS.isTab ? 500 / 10 : w / 10,
height: DDS.isTab ? (w * 0.6) / 10 : w / 10, height: DDS.isTab ? 500 / 10 : w / 10,
backgroundColor: color, backgroundColor: color,
borderRadius: 100, borderRadius: 100,
justifyContent: 'center', justifyContent: 'center',
@@ -380,7 +380,7 @@ export const ActionSheetComponent = ({
key={rowItem.name} key={rowItem.name}
style={{ style={{
alignItems: 'center', alignItems: 'center',
width: DDS.isTab ? (w * 0.6) / rowItems.length : w / rowItems.length, width: DDS.isTab ? 500 / rowItems.length : w / rowItems.length,
}}> }}>
<Icon <Icon
style={{ style={{
@@ -391,16 +391,17 @@ export const ActionSheetComponent = ({
alignItems: 'center', alignItems: 'center',
textAlign: 'center', textAlign: 'center',
textAlignVertical: 'center', textAlignVertical: 'center',
marginBottom: DDS.isTab ? 7 : 3.5,
}} }}
name={rowItem.icon} name={rowItem.icon}
size={SIZE.lg} size={DDS.isTab ? SIZE.xl : SIZE.lg}
color={colors.accent} color={colors.accent}
/> />
<Text <Text
style={{ style={{
fontFamily: WEIGHT.regular, fontFamily: WEIGHT.regular,
fontSize: SIZE.xs + 1, fontSize: DDS.isTab ? SIZE.sm : SIZE.xs + 2,
color: colors.pri, color: colors.pri,
}}> }}>
{rowItem.name} {rowItem.name}
@@ -423,7 +424,7 @@ export const ActionSheetComponent = ({
justifyContent: 'space-between', justifyContent: 'space-between',
alignItems: 'flex-end', alignItems: 'flex-end',
paddingHorizontal: 12, paddingHorizontal: 12,
paddingVertical: pv + 5, paddingVertical: pv,
}}> }}>
<View <View
style={{ style={{
@@ -485,7 +486,7 @@ export const ActionSheetComponent = ({
paddingBottom: 15, paddingBottom: 15,
backgroundColor: colors.bg, backgroundColor: colors.bg,
width: '100%', width: '100%',
paddingHorizontal: 12, paddingHorizontal: 0,
}}> }}>
<View <View
style={{ style={{
@@ -564,6 +565,14 @@ export const ActionSheetComponent = ({
{columnItems.length > 0 ? ( {columnItems.length > 0 ? (
<View>{columnItemsData.map(_renderColumnItem)}</View> <View>{columnItemsData.map(_renderColumnItem)}</View>
) : null} ) : null}
{DDS.isTab ? (
<View
style={{
height: 20,
}}
/>
) : null}
</View> </View>
); );
}; };

View File

@@ -330,13 +330,26 @@ export class DialogManager extends Component {
<> <>
<ActionSheet <ActionSheet
ref={ref => (this.actionSheet = ref)} ref={ref => (this.actionSheet = ref)}
customStyles={{ containerStyle={{
backgroundColor: colors.bg, backgroundColor: colors.bg,
width: DDS.isTab ? '60%' : '100%', width: DDS.isTab ? 500 : '100%',
alignSelf: 'center', alignSelf: DDS.isTab ? 'flex-end' : 'center',
marginRight: DDS.isTab ? 12 : null,
borderRadius: 10,
marginBottom: DDS.isTab ? 50 : 0,
}} }}
extraScroll={DDS.isTab ? 50 : 0}
indicatorColor={colors.shade} indicatorColor={colors.shade}
initialOffsetFromBottom={0.5} footerAlwaysVisible={DDS.isTab}
footerHeight={DDS.isTab ? 20 : 80}
footerStyle={
DDS.isTab
? {
borderRadius: 10,
}
: null
}
initialOffsetFromBottom={DDS.isTab ? 1 : 0.5}
bounceOnOpen={true} bounceOnOpen={true}
gestureEnabled={true} gestureEnabled={true}
onClose={() => { onClose={() => {