Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
[PAY-1319] Fix emoji keyboard overlapping chat text input
Browse files Browse the repository at this point in the history
  • Loading branch information
dharit-tan committed Jun 21, 2023
1 parent 54e3e34 commit 01953ef
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 10 deletions.
5 changes: 5 additions & 0 deletions packages/common/src/store/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ import {
import addToPlaylistReducer, {
AddToPlaylistState
} from './ui/add-to-playlist/reducer'
import bottomTabBarReducer, {
BottomTabBarState
} from './ui/bottom-tab-bar/slice'
import buyAudioReducer from './ui/buy-audio/slice'
import collectibleDetailsReducer, {
CollectibleDetailsState
Expand Down Expand Up @@ -188,6 +191,7 @@ export const reducers = () => ({
modals: modalsReducer,
musicConfetti: musicConfettiReducer,
nowPlaying: nowPlayingReducer,
bottomTabBar: bottomTabBarReducer,
reactions: reactionsReducer,
remixSettings: remixSettingsReducer,
shareSoundToTikTokModal: shareSoundToTikTokModalReducer,
Expand Down Expand Up @@ -307,6 +311,7 @@ export type CommonState = {
modals: ModalsState
musicConfetti: MusicConfettiState
nowPlaying: NowPlayingState
bottomTabBar: BottomTabBarState
reactions: ReactionsState
relatedArtists: RelatedArtistsState
remixSettings: RemixSettingsState
Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/store/ui/bottom-tab-bar/selectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { CommonState } from 'store/commonStore'

export const getBottomTabBarHeight = (state: CommonState) =>
state.ui.bottomTabBar.bottomTabBarHeight
29 changes: 29 additions & 0 deletions packages/common/src/store/ui/bottom-tab-bar/slice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'

export type BottomTabBarState = {
bottomTabBarHeight: number
}

const initialState: BottomTabBarState = {
bottomTabBarHeight: 0
}

const slice = createSlice({
name: 'ui/bottom-tab-bar',
initialState,
reducers: {
setBottomTabBarHeight: (
state,
action: PayloadAction<{
height: number
}>
) => {
const { height } = action.payload
state.bottomTabBarHeight = height
}
}
})

export const { setBottomTabBarHeight } = slice.actions
export const actions = slice.actions
export default slice.reducer
6 changes: 6 additions & 0 deletions packages/common/src/store/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,9 @@ export {
} from './search-users-modal/slice'
export * as searchUsersModalSelectors from './search-users-modal/selectors'
export { default as searchUsersModalSagas } from './search-users-modal/sagas'

export {
default as bottomTabBarUIReducer,
actions as bottomTabBarUIActions
} from './bottom-tab-bar/slice'
export * as bottomTabBarUISelectors from './bottom-tab-bar/selectors'
45 changes: 38 additions & 7 deletions packages/mobile/src/screens/app-screen/AppTabBar.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,60 @@
import { useRef } from 'react'
import { useCallback, useRef } from 'react'

import { bottomTabBarUIActions } from '@audius/common'
import type { BottomTabBarProps } from '@react-navigation/bottom-tabs'
import { Animated } from 'react-native'
import { Animated, Dimensions, View } from 'react-native'
import { useDispatch } from 'react-redux'

import { BottomTabBar } from 'app/components/bottom-tab-bar'
import { FULL_DRAWER_HEIGHT } from 'app/components/drawer'
import { NowPlayingDrawer } from 'app/components/now-playing-drawer'
import { makeStyles } from 'app/styles'

const { setBottomTabBarHeight } = bottomTabBarUIActions

const useStyles = makeStyles(({ palette }) => ({
bottomBarContainer: {
zIndex: 4,
elevation: 4
}
}))

type TabBarProps = BottomTabBarProps

const screenHeight = Dimensions.get('screen').height

export const AppTabBar = (props: TabBarProps) => {
const { navigation, state } = props
const styles = useStyles()
const dispatch = useDispatch()
// Set handlers for the NowPlayingDrawer and BottomTabBar
// When the drawer is open, the bottom bar should hide (animated away).
// When the drawer is closed, the bottom bar should reappear (animated in).
const translationAnim = useRef(new Animated.Value(FULL_DRAWER_HEIGHT)).current

const viewRef = useRef<View | null>(null)
const handleOnLayout = useCallback(() => {
if (viewRef.current) {
viewRef.current.measure((x, y, width, height, pageX, pageY) => {
dispatch(setBottomTabBarHeight({ height: screenHeight - pageY }))
})
}
}, [dispatch])

return (
<>
<NowPlayingDrawer translationAnim={translationAnim} />
<BottomTabBar
translationAnim={translationAnim}
navigation={navigation}
state={state}
/>
<View
style={styles.bottomBarContainer}
onLayout={handleOnLayout}
ref={viewRef}
>
<BottomTabBar
translationAnim={translationAnim}
navigation={navigation}
state={state}
/>
</View>
</>
)
}
9 changes: 6 additions & 3 deletions packages/mobile/src/screens/chat-screen/ChatScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
encodeUrlName,
isEarliestUnread,
playerSelectors,
useCanSendMessage
useCanSendMessage,
bottomTabBarUISelectors
} from '@audius/common'
import { Portal } from '@gorhom/portal'
import { useFocusEffect } from '@react-navigation/native'
Expand Down Expand Up @@ -85,6 +86,7 @@ const {
} = chatActions
const { getUserId } = accountSelectors
const { getHasTrack } = playerSelectors
const { getBottomTabBarHeight } = bottomTabBarUISelectors

const messages = {
title: 'Messages',
Expand Down Expand Up @@ -239,6 +241,7 @@ export const ChatScreen = () => {
)
const { canSendMessage, firstOtherUser: otherUser } =
useCanSendMessage(chatId)
const bottomTabBarHeight = useSelector(getBottomTabBarHeight)

// A ref so that the unread separator doesn't disappear immediately when the chat is marked as read
// Using a ref instead of state here to prevent unwanted flickers.
Expand Down Expand Up @@ -565,8 +568,8 @@ export const ChatScreen = () => {
<KeyboardAvoidingView
keyboardShowingOffset={
hasCurrentlyPlayingTrack
? PLAY_BAR_HEIGHT + BOTTOM_BAR_HEIGHT
: BOTTOM_BAR_HEIGHT
? PLAY_BAR_HEIGHT + bottomTabBarHeight
: bottomTabBarHeight
}
style={[
styles.keyboardAvoiding,
Expand Down

0 comments on commit 01953ef

Please sign in to comment.