fix swipe gesture

This commit is contained in:
ammarahm-ed
2020-12-06 09:52:52 +05:00
parent 4583a00e4d
commit fbc293696b

View File

@@ -78,6 +78,34 @@ let updatedDimensions = {
let currentScroll = 0; let currentScroll = 0;
let startLocation = 0; let startLocation = 0;
const _responder = (e) => {
startLocation = e.nativeEvent.pageY;
_handleTouch();
return false;
};
const _moveResponder = (e) => {
_handleTouch();
return false;
};
const _handleTouch = () => {
{
if (currentTab === 1 && startLocation > updatedDimensions.height - 70) {
if (currentScroll === 0 || currentScroll === 1) {
tabBarRef.current?.setScrollEnabled(false);
}
} else {
tabBarRef.current?.setScrollEnabled(true);
}
}
};
const _onTouchEnd = (e) => {
startLocation = 0;
tabBarRef.current?.setScrollEnabled(true);
};
const AppStack = React.memo( const AppStack = React.memo(
() => { () => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
@@ -161,7 +189,6 @@ const AppStack = React.memo(
} }
function setDeviceMode(current, size) { function setDeviceMode(current, size) {
eSendEvent(current !== 'mobile' ? eCloseSideMenu : eOpenSideMenu); eSendEvent(current !== 'mobile' ? eCloseSideMenu : eOpenSideMenu);
setMode(current); setMode(current);
dispatch({type: Actions.DEVICE_MODE, state: current}); dispatch({type: Actions.DEVICE_MODE, state: current});
@@ -179,25 +206,6 @@ const AppStack = React.memo(
} }
} }
const _responder = (e) => {
startLocation = e.nativeEvent.pageX;
const swiperLeftAreaLocation = 70;
const swiperRightAreaLocation = movedAway
? dimensions.width - 150
: dimensions.width - 1;
let pageX = e.nativeEvent.pageX;
startLocation = e.nativeEvent.pageX;
if (pageX <= swiperLeftAreaLocation || pageX >= swiperRightAreaLocation) {
tabBarRef.current?.setScrollEnabled(true);
} else {
if (currentScroll === 0 || currentScroll === 1) {
console.log(currentScroll);
tabBarRef.current?.setScrollEnabled(false);
}
}
return false;
};
return ( return (
<View <View
onLayout={_onLayout} onLayout={_onLayout}
@@ -207,21 +215,8 @@ const AppStack = React.memo(
height: '100%', height: '100%',
backgroundColor: colors.bg, backgroundColor: colors.bg,
}} }}
onMoveShouldSetResponder={e => { onMoveShouldSetResponder={_moveResponder}
const swiperLeftAreaLocation = 70; onTouchEnd={_onTouchEnd}
const swiperRightAreaLocation = movedAway
? dimensions.width - 150
: dimensions.width - 1;
if (startLocation <= swiperLeftAreaLocation || startLocation >= swiperRightAreaLocation) {
tabBarRef.current?.setScrollEnabled(true);
} else {
if (currentScroll === 0 || currentScroll === 1) {
console.log(currentScroll);
tabBarRef.current?.setScrollEnabled(false);
}
}
return false;
}}
onStartShouldSetResponder={_responder}> onStartShouldSetResponder={_responder}>
{mode && ( {mode && (
<ScrollableTabView <ScrollableTabView