Skip to content

Commit da8ce9f

Browse files
sh1zzleimdevan
authored andcommitted
Fix Android edge-to-edge display issue in modal
- Use SafeAreaView from react-native-safe-area-context for better edge-to-edge support on Android - Conditionally apply SafeAreaContextView only on Android to respect safe area insets - Keep existing SafeAreaView for iOS to maintain backward compatibility - Add react-native-safe-area-context as peer dependency Fixes issue where dropdown modal content would extend under system UI (status bar, navigation bar) on Android devices with edge-to-edge display enabled.
1 parent 17cc712 commit da8ce9f

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@
6464
"typescript": "^5.2.2"
6565
},
6666
"peerDependencies": {
67-
"react": "*",
68-
"react-native": "*",
69-
"react-native-gesture-handler": "*"
67+
"react": "^18.2.0",
68+
"react-native": "^0.72.5",
69+
"react-native-safe-area-context": "^4.0.0",
70+
"react-native-gesture-handler": "^2.18.0"
7071
}
7172
}

src/components/Picker.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
Modal,
1818
Platform,
1919
SafeAreaView,
20+
StatusBar,
2021
StyleSheet,
2122
Text,
2223
TextInput,
@@ -25,6 +26,9 @@ import {
2526
} from 'react-native';
2627

2728
import { FlatList, ScrollView } from 'react-native-gesture-handler';
29+
30+
// Import SafeAreaView from react-native-safe-area-context for better edge-to-edge support
31+
import { SafeAreaView as SafeAreaContextView } from 'react-native-safe-area-context';
2832
import {
2933
ASCII_CODE,
3034
BADGE_COLORS,
@@ -904,7 +908,15 @@ function Picker({
904908
* @returns {object}
905909
*/
906910
const _modalContentContainerStyle = useMemo(
907-
() => [THEME.modalContentContainer, ...[modalContentContainerStyle].flat()],
911+
() => [
912+
THEME.modalContentContainer,
913+
// Add edge-to-edge support for Android
914+
Platform.OS === 'android' && {
915+
flex: 1,
916+
backgroundColor: THEME.modalContentContainer.backgroundColor || '#FFFFFF',
917+
},
918+
...[modalContentContainerStyle].flat()
919+
],
908920
[modalContentContainerStyle, THEME],
909921
);
910922

@@ -1936,13 +1948,20 @@ function Picker({
19361948
presentationStyle='fullScreen'
19371949
onRequestClose={onRequestCloseModal}
19381950
{...modalProps}>
1939-
<SafeAreaView style={_modalContentContainerStyle}>
1940-
{SearchComponent}
1941-
{DropDownFlatListComponent}
1942-
</SafeAreaView>
1951+
{Platform.OS === 'android' ? (
1952+
<SafeAreaContextView style={_modalContentContainerStyle} edges={['top', 'bottom', 'left', 'right']}>
1953+
{SearchComponent}
1954+
{DropDownFlatListComponent}
1955+
</SafeAreaContextView>
1956+
) : (
1957+
<SafeAreaView style={_modalContentContainerStyle}>
1958+
{SearchComponent}
1959+
{DropDownFlatListComponent}
1960+
</SafeAreaView>
1961+
)}
19431962
</Modal>
19441963
),
1945-
[open, SearchComponent, _modalContentContainerStyle, modalProps],
1964+
[open, SearchComponent, DropDownFlatListComponent, _modalContentContainerStyle, modalProps],
19461965
);
19471966

19481967
/**

0 commit comments

Comments
 (0)