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

Fix safe area insets in fullscreen mode #606

Merged
merged 2 commits into from
Jan 21, 2025
Merged
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
25 changes: 16 additions & 9 deletions screens/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React, { useCallback, useContext, useEffect, useRef, useState } from 'rea
import { useTranslation } from 'react-i18next';
import { BackHandler, Platform, StyleSheet, View } from 'react-native';
import { ThemeContext } from 'react-native-elements';
import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

import AudioPlayer from '../components/AudioPlayer';
import ErrorView from '../components/ErrorView';
Expand Down Expand Up @@ -122,11 +122,18 @@ const HomeScreen = observer(() => {
}
}, [ httpErrorStatus ]);

// When not in fullscreen, the top adjustment is handled by the spacer View for iOS
const safeAreaEdges = [ 'right', 'left' ];
if (Platform.OS !== 'ios' || rootStore.isFullscreen) {
safeAreaEdges.push('top');
// NOTE: We use a standard View and insets to workaround https://github.com/AppAndFlow/react-native-safe-area-context/issues/204
const safeAreaPadding = {};
if (!rootStore.isFullscreen) {
safeAreaPadding.paddingLeft = insets.left;
safeAreaPadding.paddingRight = insets.right;

// When not in fullscreen, the top adjustment is handled by the spacer View for iOS
if (Platform.OS !== 'ios') {
safeAreaPadding.paddingTop = insets.top;
}
}

// Hide webview until loaded
const webviewStyle = (isLoading || httpErrorStatus) ? StyleSheet.compose(styles.container, styles.loading) : styles.container;

Expand All @@ -136,12 +143,12 @@ const HomeScreen = observer(() => {
const server = rootStore.serverStore.servers[rootStore.settingStore.activeServer];

return (
<SafeAreaView
<View
style={{
...styles.container,
backgroundColor: rootStore.isFullscreen ? Colors.black : theme.colors.background
...safeAreaPadding,
backgroundColor: rootStore.isFullscreen ? Colors.blue : theme.colors.background
}}
edges={safeAreaEdges}
>
{Platform.OS === 'ios' && !rootStore.isFullscreen && (
<View style={{
Expand Down Expand Up @@ -217,7 +224,7 @@ const HomeScreen = observer(() => {
message={t('home.errors.invalidServer.description')}
/>
)}
</SafeAreaView>
</View>
);
});

Expand Down
24 changes: 8 additions & 16 deletions screens/__tests__/__snapshots__/HomeScreen.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`HomeScreen should render ErrorView when invalid server exists 1`] = `
<RNCSafeAreaView
edges={
Array [
"right",
"left",
]
}
<View
style={
Object {
"backgroundColor": undefined,
"flex": 1,
"paddingLeft": 0,
"paddingRight": 0,
}
}
>
Expand Down Expand Up @@ -101,21 +97,17 @@ exports[`HomeScreen should render ErrorView when invalid server exists 1`] = `
testID="error-view-details"
/>
</View>
</RNCSafeAreaView>
</View>
`;

exports[`HomeScreen should render correctly 1`] = `
<RNCSafeAreaView
edges={
Array [
"right",
"left",
]
}
<View
style={
Object {
"backgroundColor": undefined,
"flex": 1,
"paddingLeft": 0,
"paddingRight": 0,
}
}
>
Expand Down Expand Up @@ -221,7 +213,7 @@ exports[`HomeScreen should render correctly 1`] = `
}
/>
</View>
</RNCSafeAreaView>
</View>
`;

exports[`HomeScreen should render null when no servers are present 1`] = `null`;
Loading