Skip to content

Commit 87bb6af

Browse files
committed
fix(mobile): remove sheet modal bottom padding when keyboard is open on android
1 parent d0571d4 commit 87bb6af

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

packages/webapp/Helpers/documentServerSideProps.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ export const documentServerSideProps = async (context: GetServerSidePropsContext
4040
const { query } = context
4141
const documentSlug = query.slugs?.at(0)
4242

43-
const { isMobile } = getDeviceInfo(context)
43+
const { isMobile, os } = getDeviceInfo(context)
4444

4545
const isTurnstileVerified = validateTurnstileAccess(context)
4646

4747
if (!isTurnstileVerified) {
4848
return {
4949
props: {
5050
showTurnstile: true,
51-
isMobile
51+
isMobile,
52+
os
5253
}
5354
}
5455
}
@@ -69,7 +70,8 @@ export const documentServerSideProps = async (context: GetServerSidePropsContext
6970
channels: channels || null,
7071
docMetadata,
7172
showTurnstile: false,
72-
isMobile
73+
isMobile,
74+
os
7375
}
7476
}
7577
} catch (error: any) {
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import MobileDetect from 'mobile-detect'
22
import { type GetServerSidePropsContext } from 'next'
33

4-
export const getDeviceInfo = (context: GetServerSidePropsContext): { isMobile: boolean } => {
4+
export const getDeviceInfo = (
5+
context: GetServerSidePropsContext
6+
): { isMobile: boolean; os: string | null } => {
57
const userAgent = context.req.headers['user-agent'] || ''
68
const device = new MobileDetect(userAgent)
9+
710
return {
8-
isMobile: Boolean(device.mobile())
11+
isMobile: Boolean(device.mobile()),
12+
os: device.os() || null
913
}
1014
}

packages/webapp/components/BottomSheet.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { useEffect, useRef } from 'react'
1+
import React, { useEffect, useMemo } from 'react'
22
import { Sheet, SheetProps } from 'react-modal-sheet'
33

4-
import { useSheetStore, useChatStore } from '@stores'
4+
import { useSheetStore, useChatStore, useStore } from '@stores'
55
import FilterModal from '@components/pages/document/components/FilterModal'
66
import NotificationModal from './notificationPanel/mobile/NotificationModal'
77
import ChatContainerMobile from './pages/document/components/chat/ChatContainerMobile'
@@ -14,6 +14,11 @@ const BottomSheet = () => {
1414
const destroyChatRoom = useChatStore((state) => state.destroyChatRoom)
1515
const setSheetContainerRef = useSheetStore((state) => state.setSheetContainerRef)
1616
const { height: keyboardHeight } = useKeyboardHeight()
17+
const { deviceDetect } = useStore((state) => state.settings)
18+
19+
const isDeviceIOS = useMemo(() => {
20+
return deviceDetect?.os() === 'iOS'
21+
}, [deviceDetect])
1722

1823
// Sync chat store with bottom sheet
1924
useEffect(() => {
@@ -62,12 +67,12 @@ const BottomSheet = () => {
6267
case 'filters':
6368
return {
6469
// Fix the bottom sheet height when keyboard is open
65-
style: { paddingBottom: keyboardHeight }
70+
style: { paddingBottom: isDeviceIOS ? keyboardHeight : 0 }
6671
}
6772
case 'chatroom':
6873
return {
6974
style: {
70-
paddingBottom: keyboardHeight
75+
paddingBottom: isDeviceIOS ? keyboardHeight : 0
7176
},
7277
disableDrag: true,
7378
disableScrollLocking: true

0 commit comments

Comments
 (0)