How to know the useful height of an iOS device in React Native?
In some very specific cases I need to set the height of a View to the full height of the device useful area (without using flex).
I was using a hardcoded "notch height" to calculate this useful height but I just discovered that the notch can have different heights depending on the device. (3 points of difference between iPhone XS and iPhone XS Max).
Is there a way to know the useful height of a device with notch and safe area?
ios reactjs react-native react-native-android react-native-ios
add a comment |
In some very specific cases I need to set the height of a View to the full height of the device useful area (without using flex).
I was using a hardcoded "notch height" to calculate this useful height but I just discovered that the notch can have different heights depending on the device. (3 points of difference between iPhone XS and iPhone XS Max).
Is there a way to know the useful height of a device with notch and safe area?
ios reactjs react-native react-native-android react-native-ios
add a comment |
In some very specific cases I need to set the height of a View to the full height of the device useful area (without using flex).
I was using a hardcoded "notch height" to calculate this useful height but I just discovered that the notch can have different heights depending on the device. (3 points of difference between iPhone XS and iPhone XS Max).
Is there a way to know the useful height of a device with notch and safe area?
ios reactjs react-native react-native-android react-native-ios
In some very specific cases I need to set the height of a View to the full height of the device useful area (without using flex).
I was using a hardcoded "notch height" to calculate this useful height but I just discovered that the notch can have different heights depending on the device. (3 points of difference between iPhone XS and iPhone XS Max).
Is there a way to know the useful height of a device with notch and safe area?
ios reactjs react-native react-native-android react-native-ios
ios reactjs react-native react-native-android react-native-ios
asked Nov 15 '18 at 12:55


JPHortaJPHorta
7341919
7341919
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
You can use the react-native-safe-area. it provides function to Get safe area inset top, bottom, left, right.
import SafeArea, { type SafeAreaInsets } from 'react-native-safe-area'
//Retrieve safe area insets for root view
SafeArea.getSafeAreaInsetsForRootView()
.then((result) => {
console.log(result)
// { safeAreaInsets: { top: 44, left: 0, bottom: 34, right: 0 } }
})
Thanks! This works nicely. My only issue now is the return of thegetSafeAreaInsetsForRootView
method being a promise, given that I want to use this to set some style variables that are exported for the whole app.
– JPHorta
Nov 19 '18 at 13:08
add a comment |
You can get the screen, which users phone, width and height from Dimensions component.
import { Dimensions } from 'react-native'
const { width, height } = Dimensions.get('window'); // if you use the width you can get the screen width by pixels. And also height is the height pixels of the phone.
const screenWidthSomePart = width * 0,6 // Some times you can get the percentage of the screen so you can use this. screen %60
If you wanna see the safe are for the Iphone X. You can use the SafeAreaView Componenet
import { SafeAreaView } from 'react-native'
return(
<SafeAreaView>
..... // your screen componenet
</SafeAreaView>
);
1
In iPhone XS the window height includes the size of the notch
– JPHorta
Nov 19 '18 at 12:03
add a comment |
As @mohammed-ashfaq said, react-native-safe-area solves the problem. However, it returns the insets with a promise and I needed those values statically.
Given that, I created react-native-static-safe-area-insets that enables access to the insets values as constants.
add a comment |
Use Dimension module from 'react-native' like there :
import { Dimensions, Platform, StatusBar } from 'react-native'
const windowHeight = Dimensions.get('window').height
const screenHeight = Dimensions.get('screen').height
In iPhone XS thewindow
andscreen
height are the same and include the size of the notch
– JPHorta
Nov 19 '18 at 12:02
Looking atRCTDeviceInfo.m
, line 75 reads:typeof (dimensions.window) window = dimensions.window; // Window and Screen are considered equal for iOS.
– JPHorta
Nov 19 '18 at 15:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319968%2fhow-to-know-the-useful-height-of-an-ios-device-in-react-native%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the react-native-safe-area. it provides function to Get safe area inset top, bottom, left, right.
import SafeArea, { type SafeAreaInsets } from 'react-native-safe-area'
//Retrieve safe area insets for root view
SafeArea.getSafeAreaInsetsForRootView()
.then((result) => {
console.log(result)
// { safeAreaInsets: { top: 44, left: 0, bottom: 34, right: 0 } }
})
Thanks! This works nicely. My only issue now is the return of thegetSafeAreaInsetsForRootView
method being a promise, given that I want to use this to set some style variables that are exported for the whole app.
– JPHorta
Nov 19 '18 at 13:08
add a comment |
You can use the react-native-safe-area. it provides function to Get safe area inset top, bottom, left, right.
import SafeArea, { type SafeAreaInsets } from 'react-native-safe-area'
//Retrieve safe area insets for root view
SafeArea.getSafeAreaInsetsForRootView()
.then((result) => {
console.log(result)
// { safeAreaInsets: { top: 44, left: 0, bottom: 34, right: 0 } }
})
Thanks! This works nicely. My only issue now is the return of thegetSafeAreaInsetsForRootView
method being a promise, given that I want to use this to set some style variables that are exported for the whole app.
– JPHorta
Nov 19 '18 at 13:08
add a comment |
You can use the react-native-safe-area. it provides function to Get safe area inset top, bottom, left, right.
import SafeArea, { type SafeAreaInsets } from 'react-native-safe-area'
//Retrieve safe area insets for root view
SafeArea.getSafeAreaInsetsForRootView()
.then((result) => {
console.log(result)
// { safeAreaInsets: { top: 44, left: 0, bottom: 34, right: 0 } }
})
You can use the react-native-safe-area. it provides function to Get safe area inset top, bottom, left, right.
import SafeArea, { type SafeAreaInsets } from 'react-native-safe-area'
//Retrieve safe area insets for root view
SafeArea.getSafeAreaInsetsForRootView()
.then((result) => {
console.log(result)
// { safeAreaInsets: { top: 44, left: 0, bottom: 34, right: 0 } }
})
answered Nov 15 '18 at 13:24


Mohammed AshfaqMohammed Ashfaq
1,6792612
1,6792612
Thanks! This works nicely. My only issue now is the return of thegetSafeAreaInsetsForRootView
method being a promise, given that I want to use this to set some style variables that are exported for the whole app.
– JPHorta
Nov 19 '18 at 13:08
add a comment |
Thanks! This works nicely. My only issue now is the return of thegetSafeAreaInsetsForRootView
method being a promise, given that I want to use this to set some style variables that are exported for the whole app.
– JPHorta
Nov 19 '18 at 13:08
Thanks! This works nicely. My only issue now is the return of the
getSafeAreaInsetsForRootView
method being a promise, given that I want to use this to set some style variables that are exported for the whole app.– JPHorta
Nov 19 '18 at 13:08
Thanks! This works nicely. My only issue now is the return of the
getSafeAreaInsetsForRootView
method being a promise, given that I want to use this to set some style variables that are exported for the whole app.– JPHorta
Nov 19 '18 at 13:08
add a comment |
You can get the screen, which users phone, width and height from Dimensions component.
import { Dimensions } from 'react-native'
const { width, height } = Dimensions.get('window'); // if you use the width you can get the screen width by pixels. And also height is the height pixels of the phone.
const screenWidthSomePart = width * 0,6 // Some times you can get the percentage of the screen so you can use this. screen %60
If you wanna see the safe are for the Iphone X. You can use the SafeAreaView Componenet
import { SafeAreaView } from 'react-native'
return(
<SafeAreaView>
..... // your screen componenet
</SafeAreaView>
);
1
In iPhone XS the window height includes the size of the notch
– JPHorta
Nov 19 '18 at 12:03
add a comment |
You can get the screen, which users phone, width and height from Dimensions component.
import { Dimensions } from 'react-native'
const { width, height } = Dimensions.get('window'); // if you use the width you can get the screen width by pixels. And also height is the height pixels of the phone.
const screenWidthSomePart = width * 0,6 // Some times you can get the percentage of the screen so you can use this. screen %60
If you wanna see the safe are for the Iphone X. You can use the SafeAreaView Componenet
import { SafeAreaView } from 'react-native'
return(
<SafeAreaView>
..... // your screen componenet
</SafeAreaView>
);
1
In iPhone XS the window height includes the size of the notch
– JPHorta
Nov 19 '18 at 12:03
add a comment |
You can get the screen, which users phone, width and height from Dimensions component.
import { Dimensions } from 'react-native'
const { width, height } = Dimensions.get('window'); // if you use the width you can get the screen width by pixels. And also height is the height pixels of the phone.
const screenWidthSomePart = width * 0,6 // Some times you can get the percentage of the screen so you can use this. screen %60
If you wanna see the safe are for the Iphone X. You can use the SafeAreaView Componenet
import { SafeAreaView } from 'react-native'
return(
<SafeAreaView>
..... // your screen componenet
</SafeAreaView>
);
You can get the screen, which users phone, width and height from Dimensions component.
import { Dimensions } from 'react-native'
const { width, height } = Dimensions.get('window'); // if you use the width you can get the screen width by pixels. And also height is the height pixels of the phone.
const screenWidthSomePart = width * 0,6 // Some times you can get the percentage of the screen so you can use this. screen %60
If you wanna see the safe are for the Iphone X. You can use the SafeAreaView Componenet
import { SafeAreaView } from 'react-native'
return(
<SafeAreaView>
..... // your screen componenet
</SafeAreaView>
);
edited Nov 19 '18 at 12:12
answered Nov 15 '18 at 13:18


Yasin UgurluYasin Ugurlu
21528
21528
1
In iPhone XS the window height includes the size of the notch
– JPHorta
Nov 19 '18 at 12:03
add a comment |
1
In iPhone XS the window height includes the size of the notch
– JPHorta
Nov 19 '18 at 12:03
1
1
In iPhone XS the window height includes the size of the notch
– JPHorta
Nov 19 '18 at 12:03
In iPhone XS the window height includes the size of the notch
– JPHorta
Nov 19 '18 at 12:03
add a comment |
As @mohammed-ashfaq said, react-native-safe-area solves the problem. However, it returns the insets with a promise and I needed those values statically.
Given that, I created react-native-static-safe-area-insets that enables access to the insets values as constants.
add a comment |
As @mohammed-ashfaq said, react-native-safe-area solves the problem. However, it returns the insets with a promise and I needed those values statically.
Given that, I created react-native-static-safe-area-insets that enables access to the insets values as constants.
add a comment |
As @mohammed-ashfaq said, react-native-safe-area solves the problem. However, it returns the insets with a promise and I needed those values statically.
Given that, I created react-native-static-safe-area-insets that enables access to the insets values as constants.
As @mohammed-ashfaq said, react-native-safe-area solves the problem. However, it returns the insets with a promise and I needed those values statically.
Given that, I created react-native-static-safe-area-insets that enables access to the insets values as constants.
answered Nov 21 '18 at 13:27


JPHortaJPHorta
7341919
7341919
add a comment |
add a comment |
Use Dimension module from 'react-native' like there :
import { Dimensions, Platform, StatusBar } from 'react-native'
const windowHeight = Dimensions.get('window').height
const screenHeight = Dimensions.get('screen').height
In iPhone XS thewindow
andscreen
height are the same and include the size of the notch
– JPHorta
Nov 19 '18 at 12:02
Looking atRCTDeviceInfo.m
, line 75 reads:typeof (dimensions.window) window = dimensions.window; // Window and Screen are considered equal for iOS.
– JPHorta
Nov 19 '18 at 15:29
add a comment |
Use Dimension module from 'react-native' like there :
import { Dimensions, Platform, StatusBar } from 'react-native'
const windowHeight = Dimensions.get('window').height
const screenHeight = Dimensions.get('screen').height
In iPhone XS thewindow
andscreen
height are the same and include the size of the notch
– JPHorta
Nov 19 '18 at 12:02
Looking atRCTDeviceInfo.m
, line 75 reads:typeof (dimensions.window) window = dimensions.window; // Window and Screen are considered equal for iOS.
– JPHorta
Nov 19 '18 at 15:29
add a comment |
Use Dimension module from 'react-native' like there :
import { Dimensions, Platform, StatusBar } from 'react-native'
const windowHeight = Dimensions.get('window').height
const screenHeight = Dimensions.get('screen').height
Use Dimension module from 'react-native' like there :
import { Dimensions, Platform, StatusBar } from 'react-native'
const windowHeight = Dimensions.get('window').height
const screenHeight = Dimensions.get('screen').height
answered Nov 15 '18 at 13:11


Vincent MenantVincent Menant
18917
18917
In iPhone XS thewindow
andscreen
height are the same and include the size of the notch
– JPHorta
Nov 19 '18 at 12:02
Looking atRCTDeviceInfo.m
, line 75 reads:typeof (dimensions.window) window = dimensions.window; // Window and Screen are considered equal for iOS.
– JPHorta
Nov 19 '18 at 15:29
add a comment |
In iPhone XS thewindow
andscreen
height are the same and include the size of the notch
– JPHorta
Nov 19 '18 at 12:02
Looking atRCTDeviceInfo.m
, line 75 reads:typeof (dimensions.window) window = dimensions.window; // Window and Screen are considered equal for iOS.
– JPHorta
Nov 19 '18 at 15:29
In iPhone XS the
window
and screen
height are the same and include the size of the notch– JPHorta
Nov 19 '18 at 12:02
In iPhone XS the
window
and screen
height are the same and include the size of the notch– JPHorta
Nov 19 '18 at 12:02
Looking at
RCTDeviceInfo.m
, line 75 reads: typeof (dimensions.window) window = dimensions.window; // Window and Screen are considered equal for iOS.
– JPHorta
Nov 19 '18 at 15:29
Looking at
RCTDeviceInfo.m
, line 75 reads: typeof (dimensions.window) window = dimensions.window; // Window and Screen are considered equal for iOS.
– JPHorta
Nov 19 '18 at 15:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319968%2fhow-to-know-the-useful-height-of-an-ios-device-in-react-native%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown