Skip to content

Commit 11d00ff

Browse files
EvanBaconnecolas
authored andcommitted
[add] SafeAreaView support for iOS 11 CSS constant
Close #1359
1 parent 8908db7 commit 11d00ff

File tree

1 file changed

+17
-4
lines changed
  • packages/react-native-web/src/exports/SafeAreaView

1 file changed

+17
-4
lines changed

packages/react-native-web/src/exports/SafeAreaView/index.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @flow
99
*/
1010

11+
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
1112
import React from 'react';
1213
import StyleSheet from '../StyleSheet';
1314
import View from '../View';
@@ -34,12 +35,24 @@ class SafeAreaView extends React.Component<ViewProps> {
3435
}
3536
}
3637

38+
const cssFunction: 'constant' | 'env' = (function() {
39+
if (
40+
canUseDOM &&
41+
window.CSS &&
42+
window.CSS.supports &&
43+
window.CSS.supports('top: constant(safe-area-inset-top)')
44+
) {
45+
return 'constant';
46+
}
47+
return 'env';
48+
})();
49+
3750
const styles = StyleSheet.create({
3851
root: {
39-
paddingTop: 'env(safe-area-inset-top)',
40-
paddingRight: 'env(safe-area-inset-right)',
41-
paddingBottom: 'env(safe-area-inset-bottom)',
42-
paddingLeft: 'env(safe-area-inset-left)'
52+
paddingTop: `${cssFunction}(safe-area-inset-top)`,
53+
paddingRight: `${cssFunction}(safe-area-inset-right)`,
54+
paddingBottom: `${cssFunction}(safe-area-inset-bottom)`,
55+
paddingLeft: `${cssFunction}(safe-area-inset-left)`
4356
}
4457
});
4558

0 commit comments

Comments
 (0)