React Native JS Api

Dimensions

本模块用于获取设备屏幕的宽高。

复制代码
const windowWidth = Dimensions.get("window").width;
const windowHeight = Dimensions.get("window").height;

PixelRatio

可以获取到设备的像素密度和字体缩放比。

复制代码
//像素密度: PixelRatio.get()
//字体缩放比: PixelRatio.getFontScale()
//将一个布局尺寸(dp)转换为像素尺寸(px): PixelRatio.getPixelSizeForLayoutSize()

Platform

获取平台信息

复制代码
Platform.OS
Platform.constants
Platform.select({
    android: {
        backgroundColor: 'green'
    },
    ios: {
        backgroundColor: 'red'
    },
    default: {
        // other platforms, web for example
        backgroundColor: 'blue'
    }
})

const Mycom = Platform.select({
  android:()=><Text>android</Text>,
  ios:()=><Text>ios</Text>
})

Share

复制代码
const result = await Share.share(
    {message:'分享的内容'},
    {dialogTitle:'标题'}
);
if (result.action === Share.sharedAction) {}

Animated

创建动画

复制代码
//1. 创建样式初始值
this.state = {
    opacity: new Animated.Value(0)
}
const fadeAnim = useRef(new Animated.Value(10)).current;
//2.定时样式值变化
Animated.timing(
  // timing方法使动画值随时间变化
  this.state.opacity, // 要变化的动画值
  {
    	toValue: 100, // 最终的动画值
      	duration: 500,
      	delay: 0
  },
).start( callback ); // 动画完成后可调用 callback 
// *timing可以换成spring,有反弹效果动画
//3.使用 <Animated.View></Animated.View> 组件

代码展示

javascript 复制代码
import{
  Dimensions,
  PixelRatio,

} from "react-native";
javascript 复制代码
return{
  const size = Dimensions.get("window");
  console.log(size);
  console.log(PixelRatio.get());
}
相关推荐
程序员大阳1 小时前
副队长JavaScript教程(55)-DOM节点增删改查
javascript·dom·增删改查·节点·克隆
程序0072 小时前
天地图实现收货地址定位
前端·javascript·css
心梦轻舞2 小时前
从 14 道面试题,彻底搞懂 Event Loop 与 Vue2 nextTick 底层原理
javascript
qq_340040883 小时前
idea2021版,vue项目的package.json不展示scripts的绿色箭头
javascript·vue.js·json
2601_968900773 小时前
玻璃深加工的工艺窗口:4 道工序的温度与时间参数边界
android·java·javascript
程序员大阳3 小时前
副队长JavaScript教程(53)-DOM操作元素的属性
javascript·dom·属性·setattribute·getattribuite
Non-existent9874 小时前
在 WPS/Excel 里做地理数据处理:功能市场 + 奥维 / Google Earth / QGIS 三种跳转实战
开发语言·javascript·ecmascript
zhougl9964 小时前
什么是 URL
javascript
螺丝钉tina5 小时前
[Playwright][01] 从 Puppeteer 到 Playwright:为什么选择 Playwright + TypeScript?
前端·javascript·typescript
大团米线5 小时前
vite多环境合并打包config
javascript·vue.js·ecmascript