Skip to content

Commit 9ab5e53

Browse files
committed
fix: modify the incorrect padding on some Android models.
1 parent 418b984 commit 9ab5e53

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

.changeset/calm-ducks-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"xlog": patch
3+
---
4+
5+
fix: modify the incorrect padding on some Android models.

src/context/global-state-context.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ interface GlobalStateContextType {
1010
}
1111
language: Language
1212
setLanguage: (language: Language) => void
13+
dimensions: {
14+
width: number
15+
height: number
16+
}
1317
}
1418

1519
export const GlobalStateContext = createContext<GlobalStateContextType | null>(null);

src/pages/Feed/index.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { FC } from "react";
22
import { useContext, useState } from "react";
33
import { Dimensions, StyleSheet } from "react-native";
4-
import Animated, { Extrapolate, interpolate, useAnimatedStyle } from "react-native-reanimated";
4+
import Animated, { Extrapolation, interpolate, useAnimatedStyle } from "react-native-reanimated";
55
import { useSafeAreaInsets } from "react-native-safe-area-context";
66

77
import type { NativeStackScreenProps } from "@react-navigation/native-stack";
@@ -10,7 +10,7 @@ import { LinearGradient } from "expo-linear-gradient";
1010
import { Stack } from "tamagui";
1111

1212
import { MasonryFeedList } from "@/components/FeedList";
13-
import { GlobalStateContext } from "@/context/global-state-context";
13+
import { GlobalStateContext, useGlobalState } from "@/context/global-state-context";
1414
import { useColors } from "@/hooks/use-colors";
1515
import type { HomeBottomTabsParamList } from "@/navigation/types";
1616

@@ -25,8 +25,6 @@ export interface Props {
2525
isShorts?: boolean
2626
}
2727

28-
const { height } = Dimensions.get("window");
29-
3028
export const FeedListLinearGradientBackground: FC = () => {
3129
const { pick } = useColors();
3230
return (
@@ -47,32 +45,34 @@ export const FeedPage: FC<NativeStackScreenProps<HomeBottomTabsParamList, "Feed"
4745
const [daysInterval, setDaysInterval] = useState<number>(7);
4846
const { isExpandedAnimValue, onScroll } = useContext(GlobalStateContext).homeFeed;
4947
const { top } = useSafeAreaInsets();
48+
const { dimensions: { height } } = useGlobalState();
5049

5150
const containerAnimStyles = useAnimatedStyle(() => {
5251
const headerHeight = interpolate(
5352
isExpandedAnimValue.value,
5453
[0, 1],
5554
[0, homeTabHeaderHeight + top],
56-
Extrapolate.CLAMP,
57-
) + extraGapBetweenIOSAndAndroid;
55+
Extrapolation.CLAMP,
56+
);
5857

5958
return {
6059
height: height - headerHeight,
6160
};
62-
}, [top, isExpandedAnimValue]);
61+
}, [top, isExpandedAnimValue, height]);
6362

6463
const innerMaskContainerAnimStyles = useAnimatedStyle(() => {
6564
const paddingTop = interpolate(
6665
isExpandedAnimValue.value,
6766
[0, 1],
6867
[0, top],
69-
Extrapolate.CLAMP,
70-
) + extraGapBetweenIOSAndAndroid;
68+
Extrapolation.CLAMP,
69+
);
7170

7271
return {
7372
paddingTop,
73+
height,
7474
};
75-
}, [top, isExpandedAnimValue]);
75+
}, [top, isExpandedAnimValue, height]);
7676

7777
return (
7878
<Stack flex={1}>
@@ -115,7 +115,6 @@ const styles = StyleSheet.create({
115115
},
116116
innerMaskContainer: {
117117
width: "100%",
118-
height,
119118
position: "absolute",
120119
bottom: 0,
121120
},

src/providers/global-state-provider.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { useMemo } from "react";
1+
import React, { useCallback, useMemo } from "react";
2+
import { View } from "react-native";
23

34
import { GlobalStateContext } from "@/context/global-state-context";
45
import { useScrollVisibilityHandler } from "@/hooks/use-scroll-visibility-handler";
@@ -14,12 +15,21 @@ interface GlobalStateProviderProps extends React.PropsWithChildren {
1415
export function GlobalStateProvider({ children }: GlobalStateProviderProps) {
1516
const [language, _setLanguage] = React.useState<keyof typeof LANGUAGES>(i18n.language as keyof typeof LANGUAGES);
1617
const { isExpandedAnimValue, onScroll } = useScrollVisibilityHandler({ scrollThreshold: homeTabHeaderHeight });
18+
const [dimensions, setDimensions] = React.useState<{
19+
width: number
20+
height: number
21+
}>(null!);
1722

18-
const setLanguage = (language: Language) => {
23+
const setLanguage = useCallback((language: Language) => {
1924
_setLanguage(language);
2025
cacheStorage.set(LANGUAGE_STORAGE_KEY, language);
2126
i18n.changeLanguage(language);
22-
};
27+
}, []);
28+
29+
const updateDimensions = useCallback((e: any) => {
30+
const { width, height } = e.nativeEvent.layout;
31+
setDimensions({ width, height });
32+
}, []);
2333

2434
const homeFeed = useMemo(() => {
2535
return {
@@ -29,8 +39,10 @@ export function GlobalStateProvider({ children }: GlobalStateProviderProps) {
2939
}, [isExpandedAnimValue, onScroll]);
3040

3141
return (
32-
<GlobalStateContext.Provider value={{ homeFeed, language, setLanguage }}>
33-
{children}
42+
<GlobalStateContext.Provider value={{ homeFeed, language, dimensions, setLanguage }}>
43+
<View style={{ flex: 1 }} onLayout={updateDimensions}>
44+
{dimensions && children}
45+
</View>
3446
</GlobalStateContext.Provider>
3547
);
3648
}

0 commit comments

Comments
 (0)