Skip to content

Commit b54f942

Browse files
committed
feat: implement SafeArea component
1 parent f3adbc1 commit b54f942

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

src/ui/Xenon.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { enableMapSet } from 'immer';
22
import { createRef, memo, useImperativeHandle, useMemo, type JSX, type ReactNode } from 'react';
33
import { Platform, StyleSheet, useWindowDimensions, View } from 'react-native';
4-
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
4+
import { SafeAreaProvider } from 'react-native-safe-area-context';
55
import { FullWindowOverlay } from 'react-native-screens';
66
import { useImmer } from 'use-immer';
77
import { MainContext } from '../contexts';
@@ -10,6 +10,7 @@ import { useConsoleInterceptor, useNetworkInterceptor } from '../hooks';
1010
import colors from '../theme/colors';
1111
import { type DebuggerState } from '../types';
1212
import { Bubble, Header, IndexedStack, Panel, SearchBar } from './components';
13+
import SafeArea from './components/common/SafeArea';
1314

1415
namespace Xenon {
1516
interface Methods {
@@ -163,10 +164,10 @@ namespace Xenon {
163164

164165
<View style={containerStyle}>
165166
<SafeAreaProvider>
166-
<SafeAreaView style={styles.safeArea}>
167-
<Header />
168-
<Panel />
169-
</SafeAreaView>
167+
{debuggerState.position === 'top' && <SafeArea inset="top" />}
168+
<Header />
169+
<Panel />
170+
{debuggerState.position === 'bottom' && <SafeArea inset="bottom" />}
170171
</SafeAreaProvider>
171172
</View>
172173

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { View } from 'react-native';
2+
import { useSafeAreaInsets, type EdgeInsets } from 'react-native-safe-area-context';
3+
4+
export default function SafeArea({
5+
inset,
6+
}: {
7+
inset: Extract<keyof EdgeInsets, 'top' | 'bottom'>;
8+
}) {
9+
return <View style={{ height: useSafeAreaInsets()[inset] }} />;
10+
}

src/ui/components/headers/DebuggerHeader.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ const DebuggerHeader = forwardRef<ScrollView, DebuggerHeaderProps>(
4545

4646
return (
4747
<HeaderComponents.Wrapper ref={ref} style={style}>
48-
<HeaderComponents.MainButtons />
49-
5048
<DebuggerHeaderItem onPress={onShowSearchInput} content={icons.search} />
5149

50+
<HeaderComponents.MainButtons />
51+
5252
<Divider type="vertical" />
5353

5454
<DebuggerHeaderItem

src/ui/components/search-bar/SearchBar.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import {
99
type TextInputSubmitEditingEventData,
1010
type ViewProps,
1111
} from 'react-native';
12-
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
12+
import { SafeAreaProvider } from 'react-native-safe-area-context';
13+
import { MainContext } from '../../../contexts';
1314
import refs, { DebuggerVisibility } from '../../../core/refs';
1415
import colors from '../../../theme/colors';
15-
import Touchable from '../common/Touchable';
16-
import Icon from '../common/Icon';
1716
import icons from '../../../theme/icons';
18-
import { MainContext } from '../../../contexts';
17+
import Icon from '../common/Icon';
18+
import Touchable from '../common/Touchable';
19+
import SafeArea from '../common/SafeArea';
1920

2021
interface SearchBarProps extends ViewProps {}
2122

@@ -48,7 +49,9 @@ const SearchBar = forwardRef<View, SearchBarProps>(({ style, ...props }, ref) =>
4849
return (
4950
<View ref={ref} style={[styles.container, style]} {...props}>
5051
<SafeAreaProvider>
51-
<SafeAreaView edges={['top']} style={styles.safeArea}>
52+
<View style={styles.barView}>
53+
<SafeArea inset="top" />
54+
5255
<View style={styles.inputWrapper}>
5356
<Icon source={icons.search} size={18} />
5457

@@ -68,11 +71,11 @@ const SearchBar = forwardRef<View, SearchBarProps>(({ style, ...props }, ref) =>
6871
onSubmitEditing={onSubmitEditing}
6972
/>
7073

71-
<Touchable onPress={onClear} style={styles.closeButton}>
74+
<Touchable hitSlop={8} onPress={onClear} style={styles.closeButton}>
7275
<Icon source={icons.close} size={12} color={colors.black} />
7376
</Touchable>
7477
</View>
75-
</SafeAreaView>
78+
</View>
7679

7780
<Touchable onPress={onHideSearchInput} style={styles.background}>
7881
<View />
@@ -88,7 +91,7 @@ const styles = StyleSheet.create({
8891
...(Platform.OS === 'android' ? { zIndex: 9999 } : {}),
8992
backgroundColor: colors.black + '80', // 80 for 50% opacity
9093
},
91-
safeArea: {
94+
barView: {
9295
backgroundColor: colors.lightGray,
9396
padding: 8,
9497
},

0 commit comments

Comments
 (0)