Skip to content

fix: adds support for changing orientations #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions packages/extras/src/components/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import { AnimatedContainer } from '@react-native-ama/animations';
import { useChecks, useTimedAction } from '@react-native-ama/core';
import * as React from 'react';
import type { PropsWithChildren } from 'react';
import * as React from 'react';
import {
Dimensions,
KeyboardAvoidingView,
LayoutChangeEvent,
Modal,
Expand All @@ -16,6 +15,7 @@ import {
StyleSheet,
View,
ViewStyle,
useWindowDimensions,
} from 'react-native';
import {
GestureHandlerRootView,
Expand Down Expand Up @@ -70,7 +70,6 @@ export type BottomSheetActions = {
isVisible: () => boolean;
};

const DEFAULT_MAX_HEIGHT = Dimensions.get('window').height * 0.9;
const isIOS = Platform.OS === 'ios';

export const BottomSheet = React.forwardRef<
Expand Down Expand Up @@ -99,7 +98,7 @@ export const BottomSheet = React.forwardRef<
overlayOpacity = 1,
footerComponent,
avoidKeyboard,
maxHeight = DEFAULT_MAX_HEIGHT,
maxHeight,
minVelocityToClose = 1000,
topInset,
onBottomSheetHidden,
Expand All @@ -124,6 +123,8 @@ export const BottomSheet = React.forwardRef<
const { keyboardHeight, keyboardFinalHeight } = useKeyboard(
shouldHandleKeyboardEvents,
);
const { height } = useWindowDimensions();
const DEFAULT_MAX_HEIGHT = React.useMemo(() => height * 0.9, [height]);

const checks = __DEV__ ? useChecks?.() : null;
const debugStyle = __DEV__ ? checks?.debugStyle : {};
Expand Down Expand Up @@ -210,8 +211,8 @@ export const BottomSheet = React.forwardRef<
});

const maxHeightValue = useDerivedValue(() => {
return maxHeight - keyboardHeight.value;
}, [keyboardHeight, maxHeight]);
return (maxHeight ?? DEFAULT_MAX_HEIGHT) - keyboardHeight.value;
}, [keyboardHeight, maxHeight, DEFAULT_MAX_HEIGHT]);

const animatedStyle = useAnimatedStyle(() => {
const keyboard = isIOS ? keyboardHeight.value : 0;
Expand All @@ -224,7 +225,7 @@ export const BottomSheet = React.forwardRef<

useDerivedValue(() => {
const maxScrollHeight = Math.ceil(
maxHeight -
(maxHeight ?? DEFAULT_MAX_HEIGHT) -
keyboardFinalHeight.value -
footerHeight -
headerHeight -
Expand All @@ -245,6 +246,7 @@ export const BottomSheet = React.forwardRef<
keyboardFinalHeight,
topInset,
maxHeight,
DEFAULT_MAX_HEIGHT,
]);

const handleOnLayout = (event: LayoutChangeEvent) => {
Expand Down
Loading