Skip to content

Commit

Permalink
fix: android keyboard issue
Browse files Browse the repository at this point in the history
Signed-off-by: Sakul <sakulbudhathoki977@gmail.com>
  • Loading branch information
sakul-budhathoki committed Apr 15, 2021
1 parent af37ff8 commit 48ba6b0
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 21 deletions.
2 changes: 1 addition & 1 deletion js/android/app/src/main/AndroidManifest.xml
Expand Up @@ -37,7 +37,7 @@
android:launchMode="singleTask"
android:exported="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
1 change: 1 addition & 0 deletions js/global.d.ts
Expand Up @@ -10,6 +10,7 @@ declare module 'react-native-audiowaveform'
declare module 'linkify-it'
declare module 'react-native-flags'
declare module 'react-native-emoji-board'
declare module 'react-native-android-keyboard-adjust'

declare module 'google-palette' {
const content: (type: string, count: number) => string[]
Expand Down
1 change: 1 addition & 0 deletions js/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions js/packages/components/chat/MultiMember.tsx
Expand Up @@ -25,6 +25,8 @@ import { MultiMemberAvatar } from '../avatars'
import { MessageList } from '@berty-tech/components/chat/MessageList'
import { useSafeAreaInsets } from 'react-native-safe-area-context'
import { ReplyReactionProvider } from './ReplyReactionContext'
import AndroidKeyboardAdjust from 'react-native-android-keyboard-adjust'
import { useFocusEffect } from '@react-navigation/native'

//
// MultiMember
Expand Down Expand Up @@ -129,6 +131,13 @@ export const MultiMember: React.FC<ScreenProps.Chat.Group> = ({ route: { params

const [isSwipe, setSwipe] = useState(true)

useFocusEffect(
React.useCallback(() => {
AndroidKeyboardAdjust?.setAdjustResize()
return () => AndroidKeyboardAdjust?.setAdjustPan()
}, []),
)

return (
<ReplyReactionProvider>
{({ activeEmojiKeyboardCid, setActiveEmojiKeyboardCid, setActivePopoverCid }) => (
Expand All @@ -147,6 +156,7 @@ export const MultiMember: React.FC<ScreenProps.Chat.Group> = ({ route: { params
<KeyboardAvoidingView
style={[flex.tiny]}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
bottomFixedViewPadding={20}
>
<MessageList id={params?.convId} {...{ setStickyDate, setShowStickyDate }} />
<ChatFooter
Expand Down
10 changes: 10 additions & 0 deletions js/packages/components/chat/OneToOne.tsx
Expand Up @@ -25,6 +25,8 @@ import { ChatDate, ChatFooter } from './common'
import { SwipeNavRecognizer } from '../shared-components/SwipeNavRecognizer'
import { MessageList } from '@berty-tech/components/chat/MessageList'
import { ReplyReactionProvider } from './ReplyReactionContext'
import AndroidKeyboardAdjust from 'react-native-android-keyboard-adjust'
import { useFocusEffect } from '@react-navigation/native'

//
// Chat
Expand Down Expand Up @@ -153,6 +155,13 @@ export const OneToOne: React.FC<ScreenProps.Chat.OneToOne> = ({ route: { params
const [showStickyDate, setShowStickyDate] = useState(false)
const [isSwipe, setSwipe] = useState(true)

useFocusEffect(
React.useCallback(() => {
AndroidKeyboardAdjust?.setAdjustResize()
return () => AndroidKeyboardAdjust?.setAdjustPan()
}, []),
)

return (
<ReplyReactionProvider>
{({ activeEmojiKeyboardCid, setActiveEmojiKeyboardCid, setActivePopoverCid }) => (
Expand All @@ -171,6 +180,7 @@ export const OneToOne: React.FC<ScreenProps.Chat.OneToOne> = ({ route: { params
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
style={[flex.tiny, { justifyContent: 'flex-start' }]}
bottomFixedViewPadding={20}
>
<MessageList
id={params?.convId}
Expand Down
64 changes: 47 additions & 17 deletions js/packages/components/shared-components/KeyboardAvoidingView.tsx
@@ -1,18 +1,48 @@
import React from 'react'
import { KeyboardAvoidingView as KeyboardAvoiding, KeyboardAvoidingViewProps } from 'react-native'
// import { useSafeAreaInsets } from 'react-native-safe-area-context'
// import { useMusicPlayer } from '@berty-tech/music-player'
// import { HEIGHT_OF_PLAYER, MARGIN_FIX } from './StickyMusicPlayer'
export const KeyboardAvoidingView: React.FC<KeyboardAvoidingViewProps> = (props) => {
// const { top } = useSafeAreaInsets()
// const {
// player: { player },
// } = useMusicPlayer()

return (
<KeyboardAvoiding
{...props}
// keyboardVerticalOffset={player ? HEIGHT_OF_PLAYER - top + MARGIN_FIX : 0}
/>
)
import React, { useState } from 'react'
import {
KeyboardAvoidingView as KeyboardAvoiding,
KeyboardAvoidingViewProps,
Platform,
StatusBar,
} from 'react-native'

import { useMusicPlayer } from '@berty-tech/music-player'
import { HEIGHT_OF_PLAYER } from './StickyMusicPlayer'

interface CustomKeyboardAvoidingViewProps extends KeyboardAvoidingViewProps {
bottomFixedViewPadding?: number
}

export const KeyboardAvoidingView: React.FC<CustomKeyboardAvoidingViewProps> = ({
bottomFixedViewPadding = 0,
...props
}) => {
const {
player: { player },
} = useMusicPlayer()

const [initialMode] = useState(!!player)

const defaultAndroidStatusBarHeight = 24
let offset = Platform.OS === 'android' ? bottomFixedViewPadding : 0

if (
Platform.OS === 'android' &&
StatusBar.currentHeight &&
StatusBar.currentHeight > defaultAndroidStatusBarHeight
) {
offset += StatusBar.currentHeight - defaultAndroidStatusBarHeight
}

if (Platform.OS === 'android' && initialMode !== !!player) {
if (player) {
offset += HEIGHT_OF_PLAYER * 2
} else {
offset -= HEIGHT_OF_PLAYER
}
} else if (player) {
offset += HEIGHT_OF_PLAYER
}

return <KeyboardAvoiding {...props} keyboardVerticalOffset={offset} />
}
Expand Up @@ -6,7 +6,6 @@ import { useMusicPlayer } from '@berty-tech/music-player'
import { useSafeAreaInsets } from 'react-native-safe-area-context'

export const HEIGHT_OF_PLAYER = 60
export const MARGIN_FIX = 10

export const StickMusicPlayer = () => {
const [{ border, padding, margin }, { windowWidth, scaleSize }] = useStyles()
Expand Down Expand Up @@ -52,8 +51,8 @@ export const StickMusicPlayer = () => {
justifyContent: 'center',
width: '100%',
position: 'relative',
marginBottom: -top + MARGIN_FIX,
marginTop: (top + 10) * scaleSize,
marginBottom: -top,
marginTop: top,
zIndex: 9,
backgroundColor: '#4F58C0',
height: HEIGHT_OF_PLAYER,
Expand Down
5 changes: 5 additions & 0 deletions js/yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 48ba6b0

Please sign in to comment.