@react-native-ohos/react-native-iphone-screen-helper
v2.3.0
Published
A library to help you design your react-native app for the iPhone
Readme
模板版本:v0.4.0
本项目基于 react-native-iphone-screen-helper 开发。
该第三方库的仓库已迁移至 Gitcode,且支持直接从 npm 下载,新的包名为:@react-native-ohos/react-native-iphone-screen-helper 版本所属关系如下:
| 三方库名称 | 三方库版本 | 发布信息 | 支持RN版本 | Autolink | 编译API版本 | 社区基线版本 | npm地址 |
| ------------ | ------------ | ------------------------------ | ------------- | ------------- |------------------------ | ------------- | ------------- |
| @react-native-ohos/react-native-iphone-screen-helper | ~ 2.3.0 | Gitcode Releases | 0.82.* | 否 | API12+ | 2.2.1 | Npm Address |
| @react-native-ohos/react-native-iphone-screen-helper | ~ 2.2.0 | Gitcode Releases | 0.77.* | 否 | API12+ | 2.1.2 | Npm Address |
| @react-native-ohos/react-native-iphone-screen-helper | ~ 2.1.1 | Gitcode Releases | 0.72.* | 否 | API12+ | 2.1.1 | Npm Address |
| @react-native-oh-tpl/react-native-iphone-screen-helper | <= 2.1.1-0.0.1@deprecated | Github Releases(deprecated) | 0.72.* | 否 | API12+ | 2.1.1 | Npm Address |
1. 安装与使用
进入到工程目录并输入以下命令:
npm
# 0.72
npm install @react-native-oh-tpl/react-native-iphone-screen-helper
# 0.77/0.82
npm install @react-native-ohos/react-native-iphone-screen-helperyarn
# 0.72
yarn add @react-native-oh-tpl/react-native-iphone-screen-helper
# 0.77/0.82
yarn add @react-native-ohos/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;2. 约束与限制
2.1. 兼容性
本文档内容基于以下版本验证通过:
- RNOH: 0.72.86; SDK: HarmonyOS 6.0.0.47 (API Version 20); IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.107;
- RNOH: 0.77.18; SDK: HarmonyOS 6.0.0.47 (API Version 20); IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.107;
- RNOH: 0.82.7; SDK: HarmonyOS 6.0.1 Release SDK; IDE: DevEco Studio 6.0.1 Release; ROM: 6.0.0.328 SP26;
3. API
[!TIP] "Platform"列表示该属性在原三方库上支持的平台。
[!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
| Name | Description | Type | Required | Platform | HarmonyOS Support | | :--- | :---------- | ---- | -------- | ---- | ------------ | | isIphoneX | 判断是否为iPhone X或更新的带刘海/灵动岛的机型 | boolean | No | All | Yes | | isDynamicIsland | 判断是否为iPhone X或灵动岛机型 | boolean | No | All | Yes | | ifIphoneX | 针对iPhone X及后续机型创建样式的方法 | stylesheets | No | All | Yes | | getStatusBarHeight | 获取状态栏高度 | number | No | All | Yes | | getBottomSpace | 获取底部安全区域高度(iPhone X为34,其他为0) | number | No | All | Yes |
4. 遗留问题
5. 其他
6. 开源协议
本项目基于 The MIT License (MIT) ,请自由地享受和参与开源。
