Skip to content
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

use reactive window dimensions for window height #21

Draft
wants to merge 1 commit into
base: discord-fork-4.6.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Keyboard, Platform } from 'react-native';
import { Keyboard, Platform, useWindowDimensions } from 'react-native';
import { runOnJS, useWorkletCallback } from 'react-native-reanimated';
import { clamp, snapPoint } from 'react-native-redash';
import {
useBottomSheetInternal,
GESTURE_SOURCE,
KEYBOARD_STATE,
SCROLLABLE_TYPE,
WINDOW_HEIGHT,
GestureEventHandlerCallbackType,
ANIMATION_SOURCE,
} from '@gorhom/bottom-sheet';
Expand Down Expand Up @@ -211,6 +210,8 @@ export const useCustomGestureEventsHandlers = () => {
animatedScrollableContentOffsetY,
]
);
const windowDimensions = useWindowDimensions();
const windowHeight = windowDimensions.height;
const handleOnEnd: GestureEventHandlerCallbackType = useWorkletCallback(
function handleOnEnd(
source,
Expand Down Expand Up @@ -265,7 +266,7 @@ export const useCustomGestureEventsHandlers = () => {
!(
Platform.OS === 'ios' &&
isScrollable &&
absoluteY > WINDOW_HEIGHT - animatedKeyboardHeight.value
absoluteY > windowHeight - animatedKeyboardHeight.value
)
) {
dismissKeyboardOnJs();
Expand Down Expand Up @@ -345,6 +346,7 @@ export const useCustomGestureEventsHandlers = () => {
animatedScrollableContentOffsetY,
isInTemporaryPosition,
isScrollableRefreshable,
windowHeight,
]
);

Expand Down
9 changes: 6 additions & 3 deletions src/components/bottomSheetContainer/BottomSheetContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
LayoutChangeEvent,
StatusBar,
StyleProp,
useWindowDimensions,
View,
ViewStyle,
} from 'react-native';
import { WINDOW_HEIGHT } from '../../constants';
import { print } from '../../utilities';
import { styles } from './styles';
import type { BottomSheetContainerProps } from './types';
Expand Down Expand Up @@ -37,6 +37,9 @@ function BottomSheetContainerComponent({
);
//#endregion

const windowDimensions = useWindowDimensions();
const windowHeight = windowDimensions.height;

//#region callbacks
const handleContainerLayout = useCallback(
function handleContainerLayout({
Expand All @@ -54,7 +57,7 @@ function BottomSheetContainerComponent({
right: 0,
bottom: Math.max(
0,
WINDOW_HEIGHT -
windowHeight -
((pageY ?? 0) + height + (StatusBar.currentHeight ?? 0))
),
};
Expand All @@ -69,7 +72,7 @@ function BottomSheetContainerComponent({
},
});
},
[containerHeight, containerOffset, containerRef]
[containerHeight, containerOffset, containerRef, windowHeight]
);
//#endregion

Expand Down
3 changes: 1 addition & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Dimensions, Platform } from 'react-native';
import Animated, { Easing } from 'react-native-reanimated';

const { height: WINDOW_HEIGHT, width: WINDOW_WIDTH } = Dimensions.get('window');
const { width: WINDOW_WIDTH } = Dimensions.get('window');
const { height: SCREEN_HEIGHT, width: SCREEN_WIDTH } = Dimensions.get('screen');

enum GESTURE_SOURCE {
Expand Down Expand Up @@ -125,7 +125,6 @@ export {
SCROLLABLE_TYPE,
SCROLLABLE_STATE,
KEYBOARD_STATE,
WINDOW_HEIGHT,
WINDOW_WIDTH,
SCREEN_HEIGHT,
SCREEN_WIDTH,
Expand Down
8 changes: 5 additions & 3 deletions src/hooks/useGestureEventsHandlersDefault.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Keyboard, Platform } from 'react-native';
import { Keyboard, Platform, useWindowDimensions } from 'react-native';
import { runOnJS, useWorkletCallback } from 'react-native-reanimated';
import { useBottomSheetInternal } from './useBottomSheetInternal';
import {
ANIMATION_SOURCE,
GESTURE_SOURCE,
KEYBOARD_STATE,
SCROLLABLE_TYPE,
WINDOW_HEIGHT,
} from '../constants';
import type {
GestureEventsHandlersHookType,
Expand Down Expand Up @@ -236,6 +235,8 @@ export const useGestureEventsHandlersDefault: GestureEventsHandlersHookType =
animatedScrollableContentOffsetY,
]
);
const windowDimensions = useWindowDimensions();
const windowHeight = windowDimensions.height;
const handleOnEnd: GestureEventHandlerCallbackType<GestureEventContextType> =
useWorkletCallback(
function handleOnEnd(
Expand Down Expand Up @@ -309,7 +310,7 @@ export const useGestureEventsHandlersDefault: GestureEventsHandlersHookType =
!(
Platform.OS === 'ios' &&
isScrollable &&
absoluteY > WINDOW_HEIGHT - animatedKeyboardHeight.value
absoluteY > windowHeight - animatedKeyboardHeight.value
)
) {
runOnJS(dismissKeyboard)();
Expand Down Expand Up @@ -378,6 +379,7 @@ export const useGestureEventsHandlersDefault: GestureEventsHandlersHookType =
animatedSnapPoints,
animatedScrollableContentOffsetY,
animateToPosition,
windowHeight,
]
);
//#endregion
Expand Down