@butternutbox/pawprint-native 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@butternutbox/pawprint-native",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "type": "module",
5
5
  "description": "ButternutBox Pawprint Design System - React Native Components",
6
6
  "main": "./dist/index.cjs",
@@ -6,8 +6,11 @@ import { useSafeAreaInsets } from "react-native-safe-area-context"
6
6
  import { useDrawerHeaderContext } from "./DrawerHeaderContext"
7
7
  import { useDrawerFooterContext } from "./DrawerFooterContext"
8
8
  import { useDrawerBodyMax } from "./DrawerBodyMaxContext"
9
+ import { useDrawerKeyboardAvoidance } from "../../../hooks/useDrawerKeyboardAvoidance"
9
10
 
10
- export type DrawerBodyProps = ScrollViewProps
11
+ export type DrawerBodyProps = ScrollViewProps & {
12
+ ignoreKeyboardAvoidance?: boolean
13
+ }
11
14
 
12
15
  const parseTokenValue = (value: string): number => parseFloat(value)
13
16
 
@@ -40,7 +43,15 @@ const StyledScrollView = styled(ScrollView)<{
40
43
  * chrome-aware `maxHeight`, scrolling beyond that.
41
44
  */
42
45
  export const DrawerBody = React.forwardRef<ScrollView, DrawerBodyProps>(
43
- ({ children, contentContainerStyle, ...props }, ref) => {
46
+ (
47
+ {
48
+ children,
49
+ contentContainerStyle,
50
+ ignoreKeyboardAvoidance = false,
51
+ ...props
52
+ },
53
+ ref
54
+ ) => {
44
55
  const theme = useTheme()
45
56
  const { spacing } = theme.tokens.components.drawer
46
57
  const { buttons } = theme.tokens.components
@@ -50,6 +61,9 @@ export const DrawerBody = React.forwardRef<ScrollView, DrawerBodyProps>(
50
61
  const providedMaxHeight = useDrawerBodyMax()
51
62
  const { height: windowHeight } = useWindowDimensions()
52
63
  const insets = useSafeAreaInsets()
64
+ const { contentContainerStyle: keyboardStyle } =
65
+ useDrawerKeyboardAvoidance()
66
+ const effectiveKeyboardStyle = ignoreKeyboardAvoidance ? {} : keyboardStyle
53
67
 
54
68
  const gap = parseTokenValue(content.slot.gap)
55
69
  const horizontalPadding = parseTokenValue(content.slot.horizontalPadding)
@@ -93,6 +107,7 @@ export const DrawerBody = React.forwardRef<ScrollView, DrawerBodyProps>(
93
107
  paddingTop: topPadding,
94
108
  paddingBottom: 0
95
109
  },
110
+ effectiveKeyboardStyle,
96
111
  contentContainerStyle
97
112
  ]}
98
113
  {...props}
@@ -0,0 +1 @@
1
+ export { useDrawerKeyboardAvoidance } from "./useDrawerKeyboardAvoidance"
@@ -0,0 +1,29 @@
1
+ import { useEffect, useState } from "react"
2
+ import { Keyboard, StyleProp, ViewStyle } from "react-native"
3
+
4
+ const useDrawerKeyboardAvoidance = (
5
+ minPadding: number = 16
6
+ ): { contentContainerStyle: StyleProp<ViewStyle> } => {
7
+ const [keyboardHeight, setKeyboardHeight] = useState(0)
8
+
9
+ useEffect(() => {
10
+ const showListener = Keyboard.addListener("keyboardDidShow", (e) => {
11
+ setKeyboardHeight(e.endCoordinates.height)
12
+ })
13
+ const hideListener = Keyboard.addListener("keyboardDidHide", () => {
14
+ setKeyboardHeight(0)
15
+ })
16
+ return () => {
17
+ showListener.remove()
18
+ hideListener.remove()
19
+ }
20
+ }, [])
21
+
22
+ return {
23
+ contentContainerStyle: {
24
+ paddingBottom: Math.max(minPadding, keyboardHeight)
25
+ }
26
+ }
27
+ }
28
+
29
+ export { useDrawerKeyboardAvoidance }
package/src/index.ts CHANGED
@@ -7,3 +7,4 @@ export { default as styled } from "@emotion/native"
7
7
  export * from "./fonts"
8
8
  export * from "./theme"
9
9
  export * from "./components"
10
+ export * from "./hooks"