From cc87f89c180d2c3f6ce7dbc93182fcfffd7744b0 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Wed, 11 Mar 2026 13:32:06 +0100 Subject: [PATCH] fix: `KeyboardAvoidingView` types union --- FabricExample/src/constants/screenNames.ts | 1 + .../src/navigation/ExamplesStack/index.tsx | 102 +-------- .../src/navigation/ExamplesStack/options.ts | 97 +++++++++ .../KeyboardAvoidingViewAutomatic/index.tsx | 203 ++++++++++++++++++ .../src/screens/Examples/Main/constants.ts | 6 + .../src/navigation/ExamplesStack/index.tsx | 98 +-------- .../src/navigation/ExamplesStack/options.ts | 97 +++++++++ .../KeyboardAvoidingViewAutomatic/index.tsx | 1 - src/components/KeyboardAvoidingView/index.tsx | 36 +--- 9 files changed, 426 insertions(+), 215 deletions(-) create mode 100644 FabricExample/src/navigation/ExamplesStack/options.ts create mode 100644 FabricExample/src/screens/Examples/KeyboardAvoidingViewAutomatic/index.tsx create mode 100644 example/src/navigation/ExamplesStack/options.ts diff --git a/FabricExample/src/constants/screenNames.ts b/FabricExample/src/constants/screenNames.ts index 268e318b82..5fd9bcba34 100644 --- a/FabricExample/src/constants/screenNames.ts +++ b/FabricExample/src/constants/screenNames.ts @@ -15,6 +15,7 @@ export enum ScreenNames { NATIVE_STACK = "NATIVE_STACK", NATIVE = "NATIVE", KEYBOARD_AVOIDING_VIEW = "KEYBOARD_AVOIDING_VIEW", + KEYBOARD_AVOIDING_VIEW_AUTOMATIC = "KEYBOARD_AVOIDING_VIEW_AUTOMATIC", ENABLED_DISABLED = "ENABLED_DISABLED", CLOSE = "CLOSE", FOCUSED_INPUT_HANDLERS = "FOCUSED_INPUT_HANDLERS", diff --git a/FabricExample/src/navigation/ExamplesStack/index.tsx b/FabricExample/src/navigation/ExamplesStack/index.tsx index 6b8bec6d41..ec42d17b07 100644 --- a/FabricExample/src/navigation/ExamplesStack/index.tsx +++ b/FabricExample/src/navigation/ExamplesStack/index.tsx @@ -14,6 +14,7 @@ import InteractiveKeyboard from "../../screens/Examples/InteractiveKeyboard"; import InteractiveKeyboardIOS from "../../screens/Examples/InteractiveKeyboardIOS"; import KeyboardAnimation from "../../screens/Examples/KeyboardAnimation"; import KeyboardAvoidingViewExample from "../../screens/Examples/KeyboardAvoidingView"; +import KeyboardAvoidingViewAutomaticExample from "../../screens/Examples/KeyboardAvoidingViewAutomatic"; import KeyboardChatScrollViewPlayground from "../../screens/Examples/KeyboardChatScrollView"; import KeyboardExtender from "../../screens/Examples/KeyboardExtender"; import KeyboardSharedTransitionExample from "../../screens/Examples/KeyboardSharedTransitions"; @@ -30,6 +31,8 @@ import ToolbarExample from "../../screens/Examples/Toolbar"; import BottomTabBar from "../BottomTabBar"; import NativeStack from "../NestedStack"; +import { options } from "./options"; + export type ExamplesStackParamList = { [ScreenNames.ANIMATED_EXAMPLE]: undefined; [ScreenNames.REANIMATED_CHAT]: undefined; @@ -44,6 +47,7 @@ export type ExamplesStackParamList = { [ScreenNames.INTERACTIVE_KEYBOARD_IOS]: undefined; [ScreenNames.NATIVE_STACK]: undefined; [ScreenNames.KEYBOARD_AVOIDING_VIEW]: undefined; + [ScreenNames.KEYBOARD_AVOIDING_VIEW_AUTOMATIC]: undefined; [ScreenNames.ENABLED_DISABLED]: undefined; [ScreenNames.CLOSE]: undefined; [ScreenNames.FOCUSED_INPUT_HANDLERS]: undefined; @@ -62,99 +66,6 @@ export type ExamplesStackParamList = { const Stack = createStackNavigator(); -const options = { - [ScreenNames.ANIMATED_EXAMPLE]: { - title: "Keyboard animation ⌨️", - }, - [ScreenNames.REANIMATED_CHAT]: { - title: "Chat", - }, - [ScreenNames.REANIMATED_CHAT_FLAT_LIST]: { - title: "Chat FlatList", - }, - [ScreenNames.EVENTS]: { - title: "Events", - }, - [ScreenNames.AWARE_SCROLL_VIEW]: { - title: "Aware scroll view", - }, - [ScreenNames.AWARE_SCROLL_VIEW_STICKY_FOOTER]: { - title: "Aware scroll view sticky footer", - }, - [ScreenNames.STATUS_BAR]: { - headerShown: false, - title: "Status bar manipulation", - }, - [ScreenNames.LOTTIE]: { - title: "Lottie animation", - }, - [ScreenNames.NON_UI_PROPS]: { - title: "Non UI Props", - }, - [ScreenNames.INTERACTIVE_KEYBOARD]: { - title: "Interactive keyboard", - }, - [ScreenNames.INTERACTIVE_KEYBOARD_IOS]: { - title: "Interactive keyboard 🍏", - }, - [ScreenNames.NATIVE_STACK]: { - title: "Native stack", - }, - [ScreenNames.KEYBOARD_AVOIDING_VIEW]: { - title: "KAV", - }, - [ScreenNames.ENABLED_DISABLED]: { - title: "Enabled/disabled", - }, - [ScreenNames.CLOSE]: { - title: "Close keyboard", - }, - [ScreenNames.FOCUSED_INPUT_HANDLERS]: { - title: "Focused input handlers", - }, - [ScreenNames.TOOLBAR]: { - title: "Toolbar", - }, - [ScreenNames.MODAL]: { - title: "Modal", - }, - [ScreenNames.BOTTOM_TAB_BAR]: { - headerShown: false, - }, - [ScreenNames.OVER_KEYBOARD_VIEW]: { - title: "View over keyboard", - }, - [ScreenNames.IMAGE_GALLERY]: { - title: "Image gallery", - }, - [ScreenNames.USE_KEYBOARD_STATE]: { - title: "useKeyboardState", - }, - [ScreenNames.LIQUID_KEYBOARD]: { - title: "Liquid keyboard", - headerShown: false, - }, - [ScreenNames.KEYBOARD_SHARED_TRANSITIONS]: { - title: "Keyboard shared transitions", - headerShown: false, - }, - [ScreenNames.KEYBOARD_EXTENDER]: { - title: "Keyboard Extender", - headerShown: false, - }, - [ScreenNames.CHAT_KIT]: { - title: "Chat Kit", - headerTintColor: "#fff", - headerStyle: { - backgroundColor: "#3A3A3C", - }, - headerBackTitle: "Back", - }, - [ScreenNames.AI_LEGEND_LIST_CHAT]: { - title: "AI LegendList Chat", - }, -}; - const ExamplesStack = () => ( ( name={ScreenNames.KEYBOARD_AVOIDING_VIEW} options={options[ScreenNames.KEYBOARD_AVOIDING_VIEW]} /> + + + Header + + + + + + Submit + + + + ); +} + +export default function KeyboardAvoidingViewAutomaticExample() { + const [behavior, setBehavior] = useState(behaviors[0]); + const [automaticOffset, setAutomaticOffset] = useState(true); + const [showModal, setShowModal] = useState(false); + const [offset, setOffset] = useState(0); + const offsets = [0, 50, 100]; + + return ( + <> + + { + const index = behaviors.indexOf(behavior); + + setBehavior( + behaviors[index === behaviors.length - 1 ? 0 : index + 1], + ); + }} + > + {behavior} + + { + const index = offsets.indexOf(offset); + + setOffset(offsets[index === offsets.length - 1 ? 0 : index + 1]); + }} + > + +{offset} + + setAutomaticOffset((v) => !v)} + > + + {automaticOffset ? "Auto" : "Manual"} + + + setShowModal(true)} + > + Modal + + + + setShowModal(false)} + > + + setShowModal(false)}> + Close + + + Modal ({automaticOffset ? "Auto" : "Manual"}) + + + + + + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + }, + content: { + flex: 1, + }, + heading: { + fontSize: 36, + marginBottom: 48, + fontWeight: "600", + }, + inner: { + padding: 24, + flex: 1, + justifyContent: "space-between", + }, + inputs: {}, + textInput: { + height: 44, + borderColor: "#000000", + borderWidth: 1, + borderRadius: 10, + marginBottom: 36, + paddingLeft: 10, + }, + button: { + marginTop: 12, + height: 44, + borderRadius: 10, + backgroundColor: "rgb(40, 64, 147)", + justifyContent: "center", + alignItems: "center", + }, + buttonText: { + fontWeight: "500", + fontSize: 16, + color: "white", + }, + settings: { + flexDirection: "row", + gap: 8, + padding: 8, + }, + settingsButton: { + paddingHorizontal: 12, + paddingVertical: 8, + borderRadius: 8, + backgroundColor: "#E8E8E8", + }, + settingsText: { + fontSize: 14, + fontWeight: "500", + }, + modalHeader: { + flexDirection: "row", + alignItems: "center", + padding: 16, + }, + closeButton: { + color: "#007AFF", + fontSize: 16, + }, + modalTitle: { + fontSize: 16, + fontWeight: "600", + flex: 1, + textAlign: "center", + marginRight: 40, + }, +}); diff --git a/FabricExample/src/screens/Examples/Main/constants.ts b/FabricExample/src/screens/Examples/Main/constants.ts index 5bad9013d5..16eedfc4e7 100644 --- a/FabricExample/src/screens/Examples/Main/constants.ts +++ b/FabricExample/src/screens/Examples/Main/constants.ts @@ -81,6 +81,12 @@ export const examples: Example[] = [ info: ScreenNames.KEYBOARD_AVOIDING_VIEW, icons: "😶", }, + { + title: "KeyboardAvoidingView Automatic", + testID: "keyboard_avoiding_view_automatic", + info: ScreenNames.KEYBOARD_AVOIDING_VIEW_AUTOMATIC, + icons: "📐", + }, { title: "Enabled/disabled", testID: "enabled_disabled", diff --git a/example/src/navigation/ExamplesStack/index.tsx b/example/src/navigation/ExamplesStack/index.tsx index 1888e7784c..ec42d17b07 100644 --- a/example/src/navigation/ExamplesStack/index.tsx +++ b/example/src/navigation/ExamplesStack/index.tsx @@ -31,6 +31,8 @@ import ToolbarExample from "../../screens/Examples/Toolbar"; import BottomTabBar from "../BottomTabBar"; import NativeStack from "../NestedStack"; +import { options } from "./options"; + export type ExamplesStackParamList = { [ScreenNames.ANIMATED_EXAMPLE]: undefined; [ScreenNames.REANIMATED_CHAT]: undefined; @@ -64,102 +66,6 @@ export type ExamplesStackParamList = { const Stack = createStackNavigator(); -const options = { - [ScreenNames.ANIMATED_EXAMPLE]: { - title: "Keyboard animation ⌨️", - }, - [ScreenNames.REANIMATED_CHAT]: { - title: "Chat", - }, - [ScreenNames.REANIMATED_CHAT_FLAT_LIST]: { - title: "Chat FlatList", - }, - [ScreenNames.EVENTS]: { - title: "Events", - }, - [ScreenNames.AWARE_SCROLL_VIEW]: { - title: "Aware scroll view", - }, - [ScreenNames.AWARE_SCROLL_VIEW_STICKY_FOOTER]: { - title: "Aware scroll view sticky footer", - }, - [ScreenNames.STATUS_BAR]: { - headerShown: false, - title: "Status bar manipulation", - }, - [ScreenNames.LOTTIE]: { - title: "Lottie animation", - }, - [ScreenNames.NON_UI_PROPS]: { - title: "Non UI Props", - }, - [ScreenNames.INTERACTIVE_KEYBOARD]: { - title: "Interactive keyboard", - }, - [ScreenNames.INTERACTIVE_KEYBOARD_IOS]: { - title: "Interactive keyboard 🍏", - }, - [ScreenNames.NATIVE_STACK]: { - title: "Native stack", - }, - [ScreenNames.KEYBOARD_AVOIDING_VIEW]: { - title: "KAV", - }, - [ScreenNames.KEYBOARD_AVOIDING_VIEW_AUTOMATIC]: { - title: "KAV Automatic", - }, - [ScreenNames.ENABLED_DISABLED]: { - title: "Enabled/disabled", - }, - [ScreenNames.CLOSE]: { - title: "Close keyboard", - }, - [ScreenNames.FOCUSED_INPUT_HANDLERS]: { - title: "Focused input handlers", - }, - [ScreenNames.TOOLBAR]: { - title: "Toolbar", - }, - [ScreenNames.MODAL]: { - title: "Modal", - }, - [ScreenNames.BOTTOM_TAB_BAR]: { - headerShown: false, - }, - [ScreenNames.OVER_KEYBOARD_VIEW]: { - title: "View over keyboard", - }, - [ScreenNames.IMAGE_GALLERY]: { - title: "Image gallery", - }, - [ScreenNames.USE_KEYBOARD_STATE]: { - title: "useKeyboardState", - }, - [ScreenNames.LIQUID_KEYBOARD]: { - title: "Liquid keyboard", - headerShown: false, - }, - [ScreenNames.KEYBOARD_SHARED_TRANSITIONS]: { - title: "Keyboard shared transitions", - headerShown: false, - }, - [ScreenNames.KEYBOARD_EXTENDER]: { - title: "Keyboard Extender", - headerShown: false, - }, - [ScreenNames.CHAT_KIT]: { - title: "Chat Kit", - headerTintColor: "#fff", - headerStyle: { - backgroundColor: "#3A3A3C", - }, - headerBackTitle: "Back", - }, - [ScreenNames.AI_LEGEND_LIST_CHAT]: { - title: "AI LegendList Chat", - }, -}; - const ExamplesStack = () => (