load app in correct mode on tablet

This commit is contained in:
ammarahm-ed
2021-02-06 13:28:27 +05:00
parent 21895541af
commit 3249e260b9
3 changed files with 37 additions and 30 deletions

View File

@@ -26,7 +26,10 @@ const App = () => {
useEffect(() => { useEffect(() => {
SettingsService.init().then((r) => { SettingsService.init().then((r) => {
DDS.checkSmallTab(Orientation.getInitialOrientation()); Orientation.getOrientation((e,r) => {
DDS.checkSmallTab(r);
console.log(r,"RESULTING",DDS.isSmallTab)
dispatch({ dispatch({
type: Actions.DEVICE_MODE, type: Actions.DEVICE_MODE,
state: DDS.isLargeTablet() state: DDS.isLargeTablet()
@@ -35,6 +38,8 @@ const App = () => {
? 'smallTablet' ? 'smallTablet'
: 'mobile', : 'mobile',
}); });
})
db.init().catch(console.log).finally(loadMainApp); db.init().catch(console.log).finally(loadMainApp);
}); });
}, []); }, []);

View File

@@ -132,14 +132,7 @@ const _onTouchEnd = (e) => {
const AppStack = React.memo( const AppStack = React.memo(
() => { () => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors} = state; const {colors, deviceMode} = state;
const [mode, setMode] = useState(
DDS.isLargeTablet()
? 'tablet'
: DDS.isSmallTab
? 'smallTablet'
: 'mobile',
);
const [dimensions, setDimensions] = useState({width, height}); const [dimensions, setDimensions] = useState({width, height});
const showFullScreenEditor = () => { const showFullScreenEditor = () => {
@@ -185,14 +178,20 @@ const AppStack = React.memo(
let size = event?.nativeEvent?.layout; let size = event?.nativeEvent?.layout;
updatedDimensions = size; updatedDimensions = size;
if (!size || (size.width === dimensions.width && mode !== null)) { if (!size || (size.width === dimensions.width && deviceMode !== null)) {
console.log(
size.width,
dimensions.width,
dimensions.height,
size.height,
'before mode',
);
DDS.setSize(size); DDS.setSize(size);
console.log(mode, 'MODE__'); console.log(deviceMode, 'MODE__');
dispatch({type: Actions.DEVICE_MODE, state: mode}); dispatch({type: Actions.DEVICE_MODE, state: deviceMode});
return; return;
} }
updatedDimensions = size;
layoutTimer = setTimeout(async () => { layoutTimer = setTimeout(async () => {
checkDeviceType(size); checkDeviceType(size);
}, 500); }, 500);
@@ -206,9 +205,12 @@ const AppStack = React.memo(
setWidthHeight(size); setWidthHeight(size);
DDS.setSize(size); DDS.setSize(size);
console.log(DDS.isLargeTablet(), size, DDS.isSmallTab);
if (DDS.isLargeTablet()) { if (DDS.isLargeTablet()) {
console.log('setting large tab');
setDeviceMode('tablet', size); setDeviceMode('tablet', size);
} else if (DDS.isSmallTab) { } else if (DDS.isSmallTab) {
console.log('setting small tab');
setDeviceMode('smallTablet', size); setDeviceMode('smallTablet', size);
} else { } else {
setDeviceMode('mobile', size); setDeviceMode('mobile', size);
@@ -217,7 +219,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);
dispatch({type: Actions.DEVICE_MODE, state: current}); dispatch({type: Actions.DEVICE_MODE, state: current});
dispatch({type: Actions.FULLSCREEN, state: false}); dispatch({type: Actions.FULLSCREEN, state: false});
@@ -257,7 +258,7 @@ const AppStack = React.memo(
onMoveShouldSetResponderCapture={_moveResponder} onMoveShouldSetResponderCapture={_moveResponder}
onTouchEnd={_onTouchEnd} onTouchEnd={_onTouchEnd}
onStartShouldSetResponderCapture={_responder}> onStartShouldSetResponderCapture={_responder}>
{mode && ( {deviceMode && (
<ScrollableTabView <ScrollableTabView
ref={tabBarRef} ref={tabBarRef}
style={{ style={{
@@ -268,7 +269,7 @@ const AppStack = React.memo(
prerenderingSiblingsNumber={Infinity} prerenderingSiblingsNumber={Infinity}
onChangeTab={onChangeTab} onChangeTab={onChangeTab}
renderTabBar={renderTabBar}> renderTabBar={renderTabBar}>
{mode !== 'tablet' && ( {deviceMode !== 'tablet' && (
<View <View
style={{ style={{
width: dimensions.width, width: dimensions.width,
@@ -279,7 +280,7 @@ const AppStack = React.memo(
alignItems: 'center', alignItems: 'center',
justifyContent: 'flex-start', justifyContent: 'flex-start',
}}> }}>
{mode === 'smallTablet' && ( {deviceMode === 'smallTablet' && (
<View <View
style={{ style={{
height: '100%', height: '100%',
@@ -293,7 +294,7 @@ const AppStack = React.memo(
style={{ style={{
height: '100%', height: '100%',
width: width:
mode === 'mobile' deviceMode === 'mobile'
? dimensions.width ? dimensions.width
: dimensions.width * 0.65, : dimensions.width * 0.65,
}}> }}>
@@ -309,7 +310,7 @@ const AppStack = React.memo(
flexDirection: 'row', flexDirection: 'row',
backgroundColor: colors.bg, backgroundColor: colors.bg,
}}> }}>
{mode === 'tablet' && ( {deviceMode === 'tablet' && (
<View <View
style={{ style={{
width: dimensions.width * 0.45, width: dimensions.width * 0.45,

View File

@@ -30,7 +30,7 @@ export class DeviceDetectionService {
this.isPhoneOrTablet(); this.isPhoneOrTablet();
this.isIosOrAndroid(); this.isIosOrAndroid();
this.detectIphoneX(); this.detectIphoneX();
//console.log(size.width > size.height,"CALC") console.log(size.width > size.height,"CALC")
this.checkSmallTab(size.width > size.height ? 'LANDSCAPE' : 'PORTRAIT'); this.checkSmallTab(size.width > size.height ? 'LANDSCAPE' : 'PORTRAIT');
} }
@@ -49,7 +49,7 @@ export class DeviceDetectionService {
this.height = Dimensions.get('screen').height; this.height = Dimensions.get('screen').height;
let deviceSize = this.getDeviceSize(); let deviceSize = this.getDeviceSize();
//console.log(deviceSize, orientation, DeviceInfo.isTablet(), 'DATA'); console.log(deviceSize, orientation, DeviceInfo.isTablet(), 'DATA');
if ( if (
(!DeviceInfo.isTablet() && orientation === 'LANDSCAPE') || (!DeviceInfo.isTablet() && orientation === 'LANDSCAPE') ||
(DeviceInfo.isTablet() && (orientation === 'PORTRAIT' || deviceSize < 9)) (DeviceInfo.isTablet() && (orientation === 'PORTRAIT' || deviceSize < 9))
@@ -63,6 +63,7 @@ export class DeviceDetectionService {
orientation === 'LANDSCAPE' && orientation === 'LANDSCAPE' &&
deviceSize > 9 deviceSize > 9
) { ) {
console.log('large tab tab')
//console.log('setting large tablet'); //console.log('setting large tablet');
this.isTab = true; this.isTab = true;
this.isPhone = false; this.isPhone = false;