React Native:如何检测带有动态岛的手机?

问题描述 投票:0回答:3

是否可以使用 React Native 来定位具有动态岛屿的手机(iPhone 14 Pro 和 iPhone 14 Pro Max)?

javascript react-native dynamic-island
3个回答
7
投票

为了补充其他答案,也可以使用 react-native-device-info

  const iPhonesWithDynamicIsland = ['iPhone15,2', 'iPhone15,3']; // iPhone 14 Pro, iPhone 14 Pro Max
  const isIphoneWithDynamicIsland = iPhonesWithDynamicIsland.includes(DeviceInfo.getDeviceId());
  console.log(isIphoneWithDynamicIsland);

或者更简单:

DeviceInfo.hasDynamicIsland()

2
投票

您可以通过使用

react-native-safe-area-context
获取其高度/顶部来简单地检测具有动态岛的 iPhone,如果是
59
那么此 iPhone 具有动态岛

import { useSafeAreaInsets } from 'react-native-safe-area-context';
const insets = useSafeAreaInsets();
console.log(insets.top == 59 ? true : false ) // has dynamic 


// this is some of the other heights of other iPhones
59 - iPhone 14 Pro / 14Pro Max
50 - iPhone 13 mini
47 - iPhone 12 / 12Pro / 13 / 13Pro / 13Pro Max / 14 / 14 Plus
44 - on iPhoneX
20 - on iOS device

1
投票

可以使用

react-native-device-info
hasDynamicIsland()
方法。

import DeviceInfo from 'react-native-device-info';

let hasDynamicIsland = DeviceInfo.hasDynamicIsland();
// true

这里是更多信息的链接react-native-device-info - hasDynamicIsland()

© www.soinside.com 2019 - 2024. All rights reserved.