-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…245) Co-authored-by: kirillzyusko <[email protected]>
- Loading branch information
1 parent
4e65942
commit 468d750
Showing
27 changed files
with
405 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./KeyboardAwareScrollView"; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
FabricExample/src/screens/Examples/AwareScrollViewStickyFooter/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React, { useCallback, useEffect, useMemo, useState } from 'react'; | ||
import { LayoutChangeEvent, View, Text, Button } from 'react-native'; | ||
import { StackScreenProps } from '@react-navigation/stack'; | ||
import { useResizeMode, KeyboardStickyView } from 'react-native-keyboard-controller'; | ||
import { useSafeAreaInsets } from 'react-native-safe-area-context'; | ||
|
||
import { ExamplesStackParamList } from '../../../navigation/ExamplesStack'; | ||
import KeyboardAwareScrollView from '../../../components/AwareScrollView'; | ||
import TextInput from '../../../components/TextInput'; | ||
import { styles } from './styles'; | ||
|
||
type Props = StackScreenProps<ExamplesStackParamList>; | ||
|
||
const variants = ['v1', 'v2', 'v3'] as const; | ||
type Variant = typeof variants[number]; | ||
|
||
export default function AwareScrollViewStickyFooter({ navigation }: Props) { | ||
useResizeMode(); | ||
|
||
const { bottom } = useSafeAreaInsets(); | ||
const [footerHeight, setFooterHeight] = useState(0); | ||
const [variant, setVariant] = useState<Variant>("v1"); | ||
|
||
const handleLayout = useCallback((evt: LayoutChangeEvent) => { | ||
setFooterHeight(evt.nativeEvent.layout.height); | ||
}, []); | ||
const offset = useMemo(() => ({closed: 0, opened: variant === "v1" ? 0 : bottom }), [bottom, variant]); | ||
const offsetV3 = useMemo(() => ({closed: -50, opened: bottom - 25}), [bottom]); | ||
|
||
useEffect(() => { | ||
navigation.setOptions({ | ||
headerRight: () => ( | ||
<Text | ||
style={styles.header} | ||
onPress={() => { | ||
const index = variants.indexOf(variant); | ||
setVariant( | ||
variants[index === variants.length - 1 ? 0 : index + 1] | ||
); | ||
}} | ||
> | ||
{variant} | ||
</Text> | ||
), | ||
}); | ||
}, [variant]); | ||
|
||
const v1v2 = variant === "v1" || variant === "v2"; | ||
|
||
return ( | ||
<View style={[styles.pageContainer, { paddingBottom: variant === "v1" ? 0 : bottom }]}> | ||
<KeyboardAwareScrollView | ||
style={styles.container} | ||
contentContainerStyle={styles.content} | ||
bottomOffset={(v1v2 ? footerHeight : 0) + 50} | ||
keyboardShouldPersistTaps="handled" | ||
> | ||
{new Array(10).fill(0).map((_, i) => ( | ||
<TextInput | ||
key={i} | ||
placeholder={`TextInput#${i}`} | ||
keyboardType={i % 2 === 0 ? 'numeric' : 'default'} | ||
/> | ||
))} | ||
</KeyboardAwareScrollView> | ||
{v1v2 && ( | ||
<KeyboardStickyView offset={offset}> | ||
<View onLayout={handleLayout} style={styles.footer}> | ||
<Text style={styles.footerText}>A mocked sticky footer</Text> | ||
<Button title="Click me" /> | ||
</View> | ||
</KeyboardStickyView> | ||
)} | ||
{variant === "v3" && ( | ||
<KeyboardStickyView offset={offsetV3}> | ||
<View style={styles.circle} /> | ||
</KeyboardStickyView> | ||
)} | ||
</View> | ||
); | ||
} |
40 changes: 40 additions & 0 deletions
40
FabricExample/src/screens/Examples/AwareScrollViewStickyFooter/styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
export const styles = StyleSheet.create({ | ||
container: { | ||
flexGrow: 1, | ||
paddingHorizontal: 16, | ||
}, | ||
content: { | ||
paddingTop: 50, | ||
}, | ||
pageContainer: { | ||
flex: 1, | ||
}, | ||
footer: { | ||
backgroundColor: 'green', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
padding: 20, | ||
width: '100%', | ||
gap: 10, | ||
}, | ||
footerText: { | ||
color: 'white', | ||
fontWeight: 'bold', | ||
}, | ||
circle: { | ||
position: 'absolute', | ||
bottom: 0, | ||
right: 30, | ||
justifyContent: "flex-end", | ||
width: 60, | ||
height: 60, | ||
borderRadius: 30, | ||
backgroundColor: "#002099", | ||
}, | ||
header: { | ||
color: 'black', | ||
paddingRight: 12, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
keywords: [react-native-keyboard-controller, KeyboardStickyView, keyboard sticky view, keyboard sticky footer, sticky view, sticky footer, keyboard, android] | ||
--- | ||
|
||
# KeyboardStickyView | ||
|
||
A `KeyboardStickyView` component seamlessly ensures that a designated view sticks to the keyboard's movements, maintaining visibility and interaction. Use it when you want to enhance the user experience by preventing important UI elements from being obscured by the keyboard, creating a smooth and user-friendly interface in your React Native application. | ||
|
||
import Lottie from 'lottie-react'; | ||
import lottie from './ksv.lottie.json'; | ||
|
||
<div style={{ display: 'flex', justifyContent: 'center', marginBottom: 20 }}> | ||
<Lottie animationData={lottie} style={{ width: 400, height: 400 }} loop /> | ||
</div> | ||
|
||
:::info `KeyboardAvoidingView` vs `KeyboardStickyView` | ||
Unlike [KeyboardAvoidingView](../keyboard-avoiding-view.mdx) the `KeyboardStickyView` just moves the content along with keyboard and not resizing the inner view. Try to compare animations of `KeyboardStickyView` and `KeyboardAvoidingView` to see a difference in details on how it works and which component is suitable for your needs. | ||
::: | ||
|
||
## Example | ||
|
||
```tsx | ||
const offset = { closed: 0, opened: 20 }; | ||
|
||
<KeyboardStickyView offset={offset}> | ||
<Footer /> | ||
</KeyboardStickyView> | ||
``` | ||
|
||
## Props | ||
|
||
### offset | ||
|
||
An object containing next properties: | ||
|
||
- **closed** - additional offset to the view when keyboard is closed. Default value is `0`. | ||
- **opened** - additional offset to the view when keyboard is opened. Default value is `0`. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./KeyboardAwareScrollView"; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.