Skip to content

Commit

Permalink
fix: keyboard avoiding
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyhw committed Mar 27, 2024
1 parent 4304af4 commit b781f99
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
3 changes: 2 additions & 1 deletion packages/ondevice-controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"@react-native-community/datetimepicker": "*",
"@react-native-community/slider": "*",
"react": "*",
"react-native": "*"
"react-native": "*",
"@gorhom/bottom-sheet": ">=4"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 2 additions & 1 deletion packages/ondevice-controls/src/types/Array.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { styled } from '@storybook/react-native-theming';

import { inputStyle } from './common';
import { useResyncValue } from './useResyncValue';
import { BottomSheetTextInput } from '@gorhom/bottom-sheet';

const Input = styled.TextInput(({ theme }) => ({
const Input = styled(BottomSheetTextInput)(({ theme }) => ({
...inputStyle(theme),
}));

Expand Down
3 changes: 2 additions & 1 deletion packages/ondevice-controls/src/types/Number.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { View } from 'react-native';

import { inputStyle } from './common';
import { useResyncValue } from './useResyncValue';
import { BottomSheetTextInput } from '@gorhom/bottom-sheet';

const Input = styled.TextInput<{ showError: boolean }>(({ theme, showError }) => {
const Input = styled(BottomSheetTextInput)<{ showError: boolean }>(({ theme, showError }) => {
const style = inputStyle(theme);
return {
...style,
Expand Down
3 changes: 2 additions & 1 deletion packages/ondevice-controls/src/types/Object.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ViewStyle } from 'react-native';

import { useResyncValue } from './useResyncValue';
import { inputStyle } from './common';
import { BottomSheetTextInput } from '@gorhom/bottom-sheet';

export interface ObjectProps {
arg: {
Expand All @@ -14,7 +15,7 @@ export interface ObjectProps {
isPristine: boolean;
}

const Input = styled.TextInput(({ theme }) => ({
const Input = styled(BottomSheetTextInput)(({ theme }) => ({
...inputStyle(theme, false),
minHeight: 60,
}));
Expand Down
3 changes: 2 additions & 1 deletion packages/ondevice-controls/src/types/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { styled } from '@storybook/react-native-theming';
import { BottomSheetTextInput } from '@gorhom/bottom-sheet';

import { inputStyle } from './common';
import { useResyncValue } from './useResyncValue';
Expand All @@ -14,7 +15,7 @@ export interface TextProps {
isPristine: boolean;
}

const Input = styled.TextInput(({ theme }) => ({
const Input = styled(BottomSheetTextInput)(({ theme }) => ({
...inputStyle(theme),
}));

Expand Down
27 changes: 13 additions & 14 deletions packages/react-native-ui/src/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
BottomSheetScrollView,
} from '@gorhom/bottom-sheet';
import { ReactNode, forwardRef, useImperativeHandle, useRef, useState } from 'react';
import { Keyboard, Platform, ScrollView, Text, View } from 'react-native';
import { useAnimatedKeyboard, useReducedMotion } from 'react-native-reanimated';
import { Keyboard, Text, View } from 'react-native';
import { useReducedMotion } from 'react-native-reanimated';
// import { Button } from './Button';
import { IconButton } from './IconButton';
import { MenuIcon } from './icon/MenuIcon';
Expand All @@ -27,6 +27,7 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { ReactRenderer } from '@storybook/react';
import { Button as Button2 } from './Button';
import { CloseIcon } from './icon/CloseIcon';
import { ScrollView } from 'react-native-gesture-handler';

const BottomSheetBackdropComponent = (backdropComponentProps: BottomSheetBackdropProps) => (
<BottomSheetBackdrop
Expand Down Expand Up @@ -66,7 +67,6 @@ export interface MobileMenuDrawerRef {
}
const MobileMenuDrawer = forwardRef<MobileMenuDrawerRef, { children: ReactNode | ReactNode[] }>(
({ children }, ref) => {
const keyboard = useAnimatedKeyboard();
const [isMobileMenuOpen, setMobileMenuOpen] = useState(false);
const reducedMotion = useReducedMotion();

Expand Down Expand Up @@ -99,18 +99,12 @@ const MobileMenuDrawer = forwardRef<MobileMenuDrawerRef, { children: ReactNode |
enableDismissOnClose
enableHandlePanningGesture
enableContentPanningGesture
// enablePanDownToClose={false}
keyboardBehavior="extend"
keyboardBlurBehavior="restore"
stackBehavior="replace"
backdropComponent={BottomSheetBackdropComponent}
>
<BottomSheetScrollView
style={{
marginBottom: Platform.select({
ios: keyboard.height,
}),
}}
keyboardShouldPersistTaps="handled"
>
<BottomSheetScrollView keyboardShouldPersistTaps="handled">
{children}
</BottomSheetScrollView>
</BottomSheetModal>
Expand Down Expand Up @@ -161,14 +155,17 @@ const MobileAddonsPanel = forwardRef<MobileAddonsPanelRef, { storyId?: string }>
style={{
paddingTop: 8,
}}
containerStyle={{}}
backgroundStyle={{
borderRadius: 0,
borderTopColor: 'lightgrey',
borderTopWidth: 1,
}}
keyboardBehavior="interactive"
keyboardBlurBehavior="restore"
enableDismissOnClose
enableHandlePanningGesture
enableContentPanningGesture
enableHandlePanningGesture={true}
enableContentPanningGesture={true}
// enablePanDownToClose={false}
stackBehavior="replace"
// backdropComponent={BottomSheetBackdropComponent}
Expand Down Expand Up @@ -209,6 +206,7 @@ const MobileAddonsPanel = forwardRef<MobileAddonsPanelRef, { storyId?: string }>
/>
</View>
<BottomSheetScrollView
keyboardShouldPersistTaps="handled"
contentContainerStyle={{
paddingBottom: insets.bottom + 16,
marginTop: 10,
Expand Down Expand Up @@ -255,6 +253,7 @@ export const Layout = ({
const addonPanelRef = useRef<MobileAddonsPanelRef>(null);
// const fullStoryName = useFullStoryName();
const insets = useSafeAreaInsets();

return (
<View style={{ flex: 1, paddingTop: insets.top }}>
<View style={{ flex: 1 }}>{children}</View>
Expand Down
5 changes: 3 additions & 2 deletions packages/react-native-ui/src/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { SearchIcon } from './icon/SearchIcon';
import { CloseIcon } from './icon/CloseIcon';
import { TextInput, View } from 'react-native';
import { DEFAULT_REF_ID } from './constants';
import { BottomSheetTextInput } from '@gorhom/bottom-sheet';

const DEFAULT_MAX_SEARCH_RESULTS = 50;

Expand Down Expand Up @@ -67,7 +68,7 @@ const SearchField = styled.View({
// marginBottom: 16,
});

const Input = styled.TextInput(({ theme }) => ({
const Input = styled(BottomSheetTextInput)(({ theme }) => ({
// appearance: 'none',
height: 32,
paddingLeft: 28,
Expand Down Expand Up @@ -304,7 +305,7 @@ export const Search = React.memo<{
</SearchIconWrapper>

<Input
ref={inputRef}
ref={inputRef as any} // TODO find solution for this
onChangeText={setInputValue}
onFocus={() => setIsOpen(true)}
onBlur={() => setIsOpen(false)}
Expand Down

0 comments on commit b781f99

Please sign in to comment.