Skip to content

Commit

Permalink
fix: adjust width to component (not window) width
Browse files Browse the repository at this point in the history
  • Loading branch information
jakex7 committed Oct 25, 2023
1 parent 18c980a commit 276326f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/components/EmojiStaticKeyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
StyleSheet,
View,
FlatList,
useWindowDimensions,
Animated,
SafeAreaView,
Platform,
Expand All @@ -25,7 +24,6 @@ const isAndroid = Platform.OS === 'android'

export const EmojiStaticKeyboard = React.memo(
() => {
const { width } = useWindowDimensions()
const {
activeCategoryIndex,
setActiveCategoryIndex,
Expand All @@ -40,6 +38,8 @@ export const EmojiStaticKeyboard = React.memo(
styles: themeStyles,
shouldAnimateScroll,
enableCategoryChangeAnimation,
width,
setWidth,
} = React.useContext(KeyboardContext)
const { keyboardState } = useKeyboardStore()
const flatListRef = React.useRef<FlatList>(null)
Expand Down Expand Up @@ -96,6 +96,7 @@ export const EmojiStaticKeyboard = React.memo(
themeStyles.container,
{ backgroundColor: theme.container },
]}
onLayout={(e) => setWidth(e.nativeEvent.layout.width)}
>
<ConditionalContainer
condition={!disableSafeArea}
Expand Down
2 changes: 2 additions & 0 deletions src/contexts/KeyboardContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export type ContextValues = {
setActiveCategoryIndex: (index: number) => void
numberOfColumns: number
width: number
setWidth: (width: number) => void
searchPhrase: string
setSearchPhrase: (phrase: string) => void
renderList: EmojisByCategory[]
Expand Down Expand Up @@ -179,6 +180,7 @@ export const defaultKeyboardValues: ContextValues = {
setActiveCategoryIndex: () => {},
numberOfColumns: 5,
width: 0,
setWidth: (_width: number) => {},
searchPhrase: '',
setSearchPhrase: (_phrase: string) => {},
renderList: [],
Expand Down
3 changes: 2 additions & 1 deletion src/contexts/KeyboardProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ProviderProps = Partial<KeyboardProps> &
}

export const KeyboardProvider: React.FC<ProviderProps> = React.memo((props) => {
const { width } = useWindowDimensions()
const [width, setWidth] = React.useState(useWindowDimensions().width)
const [activeCategoryIndex, setActiveCategoryIndex] = React.useState(0)
const [shouldAnimateScroll, setShouldAnimateScroll] = React.useState(true)
const [searchPhrase, setSearchPhrase] = React.useState('')
Expand Down Expand Up @@ -181,6 +181,7 @@ export const KeyboardProvider: React.FC<ProviderProps> = React.memo((props) => {
setActiveCategoryIndex,
numberOfColumns: numberOfColumns.current,
width,
setWidth,
searchPhrase,
setSearchPhrase,
renderList,
Expand Down

0 comments on commit 276326f

Please sign in to comment.