模板版本:v0.2.2
[!TIP] Github 地址
请到三方库的 Releases 发布地址查看配套的版本信息:@react-native-oh-tpl/react-native-iphone-screen-helper Releases 。对于未发布到npm的旧版本,请参考安装指南安装tgz包。
进入到工程目录并输入以下命令:
npm install @react-native-oh-tpl/react-native-iphone-screen-helper
yarn add @react-native-oh-tpl/react-native-iphone-screen-helper
下面的代码展示了这个库的基本使用场景:
[!WARNING] 使用时 import 的库名不变。
import React, { useState, useEffect } from 'react';
import { getStatusBarHeight } from 'react-native-iphone-screen-helper'
import { View } from 'react-native';
const ScreenHelperDemo: React.FC = (): JSX.Element => {
const [currentHeight, setCurrentHeight] = useState<number>(0)
useEffect(() => {
const barHeight = getStatusBarHeight()
setCurrentHeight(barHeight)
}, [])
return (
<>
<View style={{ height: currentHeight, borderBottomWidth: 1 }} />
</>
)
}
export default ScreenHelperDemo;
要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:@react-native-oh-tpl/react-native-iphone-screen-helper Releases
[!TIP] "Platform"列表示该属性在原三方库上支持的平台。
[!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
Name | Description | Type | Required | Platform | HarmonyOS Support |
---|---|---|---|---|---|
isIphoneX | returns - true if you're running on an iPhone X or a newer model with a notch or dynamic island. |
boolean | No | All | Yes |
isDynamicIsland | returns - true if you're running on an iPhone X or dynamic island. |
boolean | No | All | Yes |
ifIphoneX | This method is for creating stylesheets with the iPhone X and later models, including those with dynamic islands, in mind. | stylesheets | No | All | Yes |
getStatusBarHeight | returns - the height of the status bar | number | No | All | Yes |
getBottomSpace | returns - the height of the bottom to fit the safe area: 34 for iPhone X and newer models with a notch or dynamic island, and 0 for other devices. |
number | No | All | Yes |
本项目基于 The MIT License (MIT) ,请自由地享受和参与开源。