Skip to content

Commit fd71727

Browse files
authored
fix: provide real safe area view (#911)
* fix(android): set SafeAreaView insets explicitly * chore(dep): force to use [email protected] * chore: not need to use forceInset * fix: use the fork to support pre-AndroidX * fix: lint * fix: ignore the line
1 parent e043138 commit fd71727

File tree

16 files changed

+118
-35
lines changed

16 files changed

+118
-35
lines changed

App.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import {
77
StatusBar,
88
Platform,
99
} from 'react-native';
10-
import { SafeAreaView } from 'react-navigation';
11-
import DeviceInfo from 'react-native-device-info';
1210
import codePush from 'react-native-code-push';
1311
import { PersistGate } from 'redux-persist/integration/react';
12+
import { SafeAreaProvider } from 'react-native-safe-area-context'; // eslint-disable-line
1413
import { colors, getStatusBarConfig } from 'config';
1514
import { getCurrentLocale, configureLocale } from 'utils';
1615
import { GitPoint } from './routes';
@@ -32,11 +31,6 @@ if (console) {
3231
console.disableYellowBox = true; // eslint-disable-line no-console
3332
}
3433

35-
if (Platform.OS === 'android' && DeviceInfo.hasNotch()) {
36-
// FIXME: real value for status bar height + notch height
37-
SafeAreaView.setStatusBarHeight(44);
38-
}
39-
4034
class App extends Component {
4135
static async initLocale() {
4236
const locale = await getCurrentLocale();
@@ -107,9 +101,11 @@ class App extends Component {
107101
return (
108102
<Provider store={configureStore}>
109103
<PersistGate loading={this.renderLogo} persistor={persistor}>
110-
<GitPoint onNavigationStateChange={this.statusBarHandler}>
111-
<StatusBar />
112-
</GitPoint>
104+
<SafeAreaProvider>
105+
<GitPoint onNavigationStateChange={this.statusBarHandler}>
106+
<StatusBar />
107+
</GitPoint>
108+
</SafeAreaProvider>
113109
</PersistGate>
114110
</Provider>
115111
);

android/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ android {
148148
}
149149

150150
dependencies {
151+
implementation project(':react-native-safe-area-context')
151152
implementation project(':react-native-webview')
152153
implementation project(':@react-native-community_async-storage')
153154
compile project(':react-native-svg')

android/app/src/main/java/com/gitpoint/MainApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Application;
44

55
import com.facebook.react.ReactApplication;
6+
import com.th3rdwave.safeareacontext.SafeAreaContextPackage;
67
import com.reactnativecommunity.webview.RNCWebViewPackage;
78
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
89
import com.horcrux.svg.SvgPackage;
@@ -40,6 +41,7 @@ public boolean getUseDeveloperSupport() {
4041
protected List<ReactPackage> getPackages() {
4142
return Arrays.<ReactPackage>asList(
4243
new MainReactPackage(),
44+
new SafeAreaContextPackage(),
4345
new RNCWebViewPackage(),
4446
new AsyncStoragePackage(),
4547
new SvgPackage(),

android/settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
rootProject.name = 'GitPoint'
2+
include ':react-native-safe-area-context'
3+
project(':react-native-safe-area-context').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-safe-area-context/android')
24
include ':react-native-webview'
35
project(':react-native-webview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview/android')
46
include ':@react-native-community_async-storage'

ios/GitPoint.xcodeproj/project.pbxproj

Lines changed: 77 additions & 6 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"react-native-parallax-scroll-view": "^0.20.1",
8383
"react-native-photo-view": "^1.5.2",
8484
"react-native-safari-view": "^2.0.0",
85+
"react-native-safe-area-context": "chinesedfan/react-native-safe-area-context#git-point",
8586
"react-native-search-bar": "^3.3.1",
8687
"react-native-simple-toast": "^0.0.8",
8788
"react-native-svg": "^6.3.1",
@@ -153,6 +154,7 @@
153154
"stylelint-processor-styled-components": "^1.0.0"
154155
},
155156
"resolutions": {
157+
"react-native-safe-area-view": "1.0.0",
156158
"react-native-tab-view": "chinesedfan/react-native-tab-view#git-point"
157159
},
158160
"jest": {

src/auth/screens/auth-profile.screen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
UserListItem,
2020
EntityInfo,
2121
} from 'components';
22-
import { colors, fonts, normalize } from 'config';
22+
import { colors, fonts, normalize, getHeaderForceInset } from 'config';
2323
import { getUser, getOrgs, getStarCount } from 'auth';
2424
import { emojifyText, openURLInView, t } from 'utils';
2525

@@ -44,7 +44,7 @@ const mapDispatchToProps = dispatch =>
4444
);
4545

4646
const StyledSafeAreaView = styled(SafeAreaView).attrs({
47-
forceInset: { top: 'always', bottom: 'never' },
47+
forceInset: getHeaderForceInset('MyProfile'),
4848
})`
4949
background-color: ${colors.primaryDark};
5050
`;

src/auth/screens/login.screen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const ModalWrapper = styled.View`
5050
const StyledSafeAreaView = styled(SafeAreaView).attrs({
5151
forceInset: Platform.select({
5252
ios: { top: 'always', bottom: 'never' },
53-
android: {},
53+
android: { top: 'never', bottom: 'never' },
5454
}),
5555
})`
5656
background-color: ${colors.githubDark};

src/auth/screens/welcome.screen.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class Welcome extends Component {
6060
CookieManager.clearAll().then(() => {
6161
auth(code, state).then(() => {
6262
getUser().then(() => {
63-
console.log('resetNavigationTo Main');
6463
resetNavigationTo('Main', navigation);
6564
});
6665
});

src/config/status-bar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ export const getStatusBarConfig = routeName =>
2626
: darkStatusBar;
2727

2828
export const getHeaderForceInset = routeName =>
29-
lightScreens.includes(routeName) ? { top: 'always', bottom: 'never' } : {};
29+
lightScreens.includes(routeName)
30+
? { top: 'always', bottom: 'never' }
31+
: {};

0 commit comments

Comments
 (0)