From aca2f42dad5b943b83f611df1bcc95ee7e1400ce Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Fri, 10 Jan 2025 13:11:38 -0800 Subject: [PATCH] adjusting keyboard avoid --- .../mobile/src/conversation/Conversation.styled.ts | 6 ++++++ app/client/mobile/src/conversation/Conversation.tsx | 8 ++++++-- app/client/mobile/src/session/useSession.hook.ts | 12 ++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/client/mobile/src/conversation/Conversation.styled.ts b/app/client/mobile/src/conversation/Conversation.styled.ts index db5d1206..7f6ce3ff 100644 --- a/app/client/mobile/src/conversation/Conversation.styled.ts +++ b/app/client/mobile/src/conversation/Conversation.styled.ts @@ -5,6 +5,11 @@ export const styles = StyleSheet.create({ conversation: { flex: 1 }, + avoid: { + width: '100%', + height: '30%', + flexShrink: 0, + }, closeIcon: { position: 'absolute', top: 0, @@ -62,6 +67,7 @@ export const styles = StyleSheet.create({ thread: { display: 'flex', flexGrow: 1, + flexShrink: 1, minHeight: 0, height: '50%', width: '100%', diff --git a/app/client/mobile/src/conversation/Conversation.tsx b/app/client/mobile/src/conversation/Conversation.tsx index 448a2760..fb9c58d0 100644 --- a/app/client/mobile/src/conversation/Conversation.tsx +++ b/app/client/mobile/src/conversation/Conversation.tsx @@ -34,6 +34,7 @@ export function Conversation({close, openDetails, wide}: {close: ()=>void, openD const [ selected, setSelected ] = useState(null as null | string); const [ sizeMenu, setSizeMenu ] = useState(false); const [ colorMenu, setColorMenu ] = useState(false); + const [avoid, setAvoid] = useState(false); const thread = useRef(); const scrolled = useRef(false); const contentHeight = useRef(0); @@ -184,7 +185,7 @@ export function Conversation({close, openDetails, wide}: {close: ()=>void, openD }); return ( - + @@ -278,10 +279,13 @@ export function Conversation({close, openDetails, wide}: {close: ()=>void, openD setAvoid(true)} onBlur={()=>setAvoid(false)} textColor={state.textColorSet ? state.textColor : undefined} outlineColor="transparent" activeOutlineColor="transparent"spellcheck={false} autoComplete="off" autoCapitalize="none" autoCorrect={false} placeholder={state.strings.newMessage} placeholderTextColor={state.textColorSet ? state.textColor : undefined} cursorColor={state.textColorSet ? state.textColor : undefined} value={state.message} onChangeText={value => actions.setMessage(value)} /> + { Platform.OS === 'ios' && avoid && () } + @@ -336,6 +340,6 @@ export function Conversation({close, openDetails, wide}: {close: ()=>void, openD - + ); } diff --git a/app/client/mobile/src/session/useSession.hook.ts b/app/client/mobile/src/session/useSession.hook.ts index 075c9598..01e06f77 100644 --- a/app/client/mobile/src/session/useSession.hook.ts +++ b/app/client/mobile/src/session/useSession.hook.ts @@ -1,4 +1,5 @@ import {useEffect, useState, useContext, useRef} from 'react'; +import { AppState } from 'react-native'; import {AppContext} from '../context/AppContext'; import {DisplayContext} from '../context/DisplayContext'; import {ContextType} from '../context/ContextType'; @@ -20,7 +21,7 @@ export function useSession() { useEffect(() => { const setStatus = (status: string) => { - if (status === 'disconnected') { + if (state.appState === 'active' && status === 'disconnected') { disconnecting.current = setTimeout(() => { updateState({ disconnected: true }); }, 4000); @@ -29,10 +30,17 @@ export function useSession() { updateState({ disconnected: false }); } } + const setAppState = (appState: string) => { + updateState({ appState }); + } const session = app.state.session; if (session) { session.addStatusListener(setStatus); - return () => session.removeStatusListener(); + const sub = AppState.addEventListener('change', setAppState); + return () => { + session.removeStatusListener(); + sub.remove(); + } } }, [app.state.session]);