Skip to content

Commit e9336cb

Browse files
committed
fixed safeArea handling, moved stretch styling to modifiers
1 parent bb87bc0 commit e9336cb

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

demo/src/screens/componentScreens/ScreenFooterScreen.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, {useState} from 'react';
22
import {StyleSheet, ScrollView} from 'react-native';
3+
import {SafeAreaProvider} from 'react-native-safe-area-context';
34
import {
45
View,
56
Text,
@@ -222,7 +223,7 @@ const ScreenFooterScreen = () => {
222223
};
223224

224225
return (
225-
<>
226+
<SafeAreaProvider>
226227
<ScrollView contentContainerStyle={styles.scrollContent} onScroll={onScroll} scrollEventThrottle={16}>
227228
<Text text60 marginB-s4>
228229
ScreenFooter Configuration
@@ -477,7 +478,7 @@ const ScreenFooterScreen = () => {
477478
>
478479
{renderFooterItems()}
479480
</ScreenFooter>
480-
</>
481+
</SafeAreaProvider>
481482
);
482483
};
483484

packages/react-native-ui-lib/src/components/screenFooter/index.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React, {useCallback, useEffect, useMemo, useState} from 'react';
22
import {LayoutChangeEvent, StyleSheet, ViewStyle} from 'react-native';
3+
import {useSafeAreaInsets} from 'react-native-safe-area-context';
34
import {Image} from 'react-native-ui-lib';
45
import Animated, {useAnimatedKeyboard, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
56
import {Keyboard} from 'uilib-native';
67
import View from '../view';
78
import Assets from '../../assets';
89
import {Colors, Shadows, Spacings} from '../../style';
910
import {asBaseComponent, Constants} from '../../commons/new';
11+
import {useKeyboardHeight} from '../../hooks';
1012
import {
1113
ScreenFooterProps,
1214
ScreenFooterLayouts,
@@ -110,7 +112,10 @@ const ScreenFooter = (props: ScreenFooterProps) => {
110112
}
111113
}, [layout, itemsFit, alignment]);
112114

113-
const {bottom: safeAreaBottom} = Constants.getSafeAreaInsets();
115+
const insets = useSafeAreaInsets();
116+
117+
const keyboardHeight = useKeyboardHeight();
118+
const isKeyboardVisible = keyboardHeight > 0;
114119

115120
const contentContainerStyle = useMemo(() => {
116121
const style: any[] = [
@@ -119,7 +124,10 @@ const ScreenFooter = (props: ScreenFooterProps) => {
119124
{alignItems, justifyContent}
120125
];
121126

122-
127+
if (useSafeArea && !isKeyboardVisible) {
128+
style.push({paddingBottom: insets.bottom});
129+
}
130+
123131
if (isSolid) {
124132
const shadowStyle = Shadows[shadow]?.top;
125133
const backgroundElevation = shadowStyle?.elevation || 0;
@@ -128,7 +136,7 @@ const ScreenFooter = (props: ScreenFooterProps) => {
128136
}
129137

130138
return style;
131-
}, [layout, alignItems, justifyContent, useSafeArea, safeAreaBottom, isSolid, shadow]);
139+
}, [layout, alignItems, justifyContent, useSafeArea, insets.bottom, isSolid, shadow, isKeyboardVisible]);
132140

133141
const solidBackgroundStyle = useMemo(() => {
134142
if (!isSolid) {
@@ -182,7 +190,7 @@ const ScreenFooter = (props: ScreenFooterProps) => {
182190

183191
if (isHorizontal && React.isValidElement(child) && itemsFit === ItemsFit.STRETCH) {
184192
return (
185-
<View key={index} style={styles.stretchItemWrapper}>
193+
<View flex row centerH key={index}>
186194
{child}
187195
</View>
188196
);
@@ -194,12 +202,12 @@ const ScreenFooter = (props: ScreenFooterProps) => {
194202

195203
const renderFooterContent = useCallback(() => {
196204
return (
197-
<View useSafeArea={useSafeArea}>
205+
<>
198206
{renderBackground()}
199207
<View testID={testID ? `${testID}.content` : undefined} style={contentContainerStyle}>
200208
{childrenArray}
201209
</View>
202-
</View>
210+
</>
203211
);
204212
}, [renderBackground, testID, contentContainerStyle, childrenArray]);
205213

@@ -255,11 +263,6 @@ const styles = StyleSheet.create({
255263
flexDirection: 'column',
256264
gap: Spacings.s3
257265
},
258-
stretchItemWrapper: {
259-
flexDirection: 'row',
260-
flex: 1,
261-
justifyContent: 'center'
262-
},
263266
background: {
264267
width: '100%',
265268
height: '100%'

0 commit comments

Comments
 (0)