React Native 一些API详解

一、Platform 获取平台属性

javascript 复制代码
// 获取平台
console.log(Platform.OS)
// 获取版本
console.log(Platform.Version)
// {"Brand": "google", "Fingerprint": "google/sdk_gphone64_x86_64/emu64xa:16/BP22.250325.006/13344233:user/release-keys", "Manufacturer": "Google", "Model": "sdk_gphone64_x86_64", "Release": "16", "Serial": "unknown", "ServerHost": "localhost:8081", "Version": 36, "isTesting": false, "reactNativeVersion": {"major": 0, "minor": 70, "patch": 6, "prerelease": null}, "uiMode": "normal"}
console.log(Platform.constants)

// 是否是pad
console.log(Platform.isPad);
// 是否是tv
console.log(Platform.isTV);

// 不同平台用不同样式
const styles = StyleSheet.create({
	box: {
		width: '100%',
        height: '100%',
		...Platform.select({ // 返回的是对象
			android: {xx:xx},
			ios: {xx:xx},
			default: {xx:xx},
		})
	}
})

二、Linking

javascript 复制代码
// 判断链接能否打开
Linking.canOpenURL('xx')
// 打开链接
Linking.openURL('xx') 
// 跳应用设置页面
Linking.openSettings()
// 获取跳转过来的url
Linking.getInitialURL()

三、PixelRatio

javascript 复制代码
// 获取屏幕像素密度
PixelRatio.get()
// 获取安卓字体缩放比例
PixelRatio.getFontScale()
// 获取尺寸的物理像素 = 尺寸* PixelRatio.get()
PixelRatio.getPixelSizeForLayoutSize(尺寸)

四、PermissionsAndroid 安装权限

javascript 复制代码
// 检查权限
PermissionsAndroid.check(xxxx).then(result => {
	// result: true/false
    if (!result) {
    	// 申请权限
        PermissionsAndroid.request(xxxx).then(status => {
        	// status: granted 允许   /   denied 拒绝
            // do sth.
        });
    }
});


// 申请多个权限
 PermissionsAndroid.requestMultiple([xxxx,xxxx])
相关推荐
中微子2 小时前
React Router 源码深度剖析解决面试中的深层次问题
前端·react.js
中微子3 小时前
React Router 面试指南:从基础到实战
前端·react.js·前端框架
前端_学习之路4 小时前
React--Fiber 架构
前端·react.js·架构
coderlin_4 小时前
BI布局拖拽 (1) 深入react-gird-layout源码
android·javascript·react.js
甜瓜看代码4 小时前
1.
react.js·node.js·angular.js
伍哥的传说4 小时前
React 实现五子棋人机对战小游戏
前端·javascript·react.js·前端框架·node.js·ecmascript·js
wen's6 小时前
React Native安卓刘海屏适配终极方案:仅需修改 AndroidManifest.xml!
android·xml·react native
小李飞飞砖6 小时前
React Native 组件间通信方式详解
javascript·react native·react.js
小李飞飞砖6 小时前
React Native 状态管理方案全面对比
javascript·react native·react.js