diff --git a/zh-cn/react-native-MJRefresh.md b/zh-cn/react-native-MJRefresh.md index 6c31e339092bb55550fb672a2c71f1db139c0338..497de0cd34da6c49ecf0a2e11e9db5de01aca5ed 100644 --- a/zh-cn/react-native-MJRefresh.md +++ b/zh-cn/react-native-MJRefresh.md @@ -1,4 +1,4 @@ -> 模板版本:v0.1.3 +> 模板版本:v0.2.0

react-native-MJRefresh

@@ -44,55 +44,72 @@ yarn add @react-native-oh-tpl/react-native-mjrefresh@file:# > [!WARNING] 使用时 import 的库名不变。 ```tsx -import React, { useState } from "react"; +import React, { Component } from "react"; import { ScrollView, Text, View } from "react-native"; import { MJRefreshControl } from "react-native-mjrefresh"; -export const MjRefreshDemo = () => { - const [state, setState] = useState<{ - message?: string; - }>({ - message: "", - }); - const { message } = state; - let mjRefreshRef: React.RefObject; - return ( - - (this.mjRefreshRef = ref)} - onRefresh={() => { - setState({ message: "正在刷新" }); - console.log("------------onRefresh"); - // 开始刷新 - this.mjRefreshRef.beginRefresh(); - // 自定义刷新结束事件 - setTimeout(() => { - console.log("------------ Finish Refresh"); - // 结束刷新 - this.mjRefreshRef.finishRefresh(); - }, 2000); - }} - onRefreshIdle={() => { - setState({ message: "下拉刷新" }); - console.log("------------onRefreshIdle"); - }} - onReleaseToRefresh={() => { - setState({ message: "释放刷新" }); - console.log("------------onReleaseToRefresh"); - }} - onPulling={() => { - setState({ message: "下拉刷新" }); - console.log("------------onPulling"); - }} - > - } - > - Refresh State:{message} - - ); +export default class MjRefreshDemo extends Component { + constructor(props) { + super(props); + } + + state = { + text : "下拉刷新", + refreshing : false + } + _onRefresh = () => { + setTimeout(() => { + this._hw && this._hw.finishRefresh(); + }, 1000); + } + render() { + return ( + this._mjrefresh = ref} + onRefresh={ + ()=>{ + this.setState({ + text:'正在刷新' + }) + console.log('onRefresh') + setTimeout(()=>{ + this._mjrefresh && this._mjrefresh.finishRefresh(); + },1000) + } + } + onRefreshIdle={()=>console.log('onRefreshIdle')} + onReleaseToRefresh={()=>{ + this.setState({ + text:'释放刷新' + }) + }} + onPulling={e=>{ + if(e.nativeEvent.percent<0.1){ + this.setState({ + text:'下拉刷新' + }) + } + }} + + HeaderComponent = { + + {this.state.text} + + } + > + + + } + > + {"mjRefresh TEST mjRefresh TEST mjRefresh TEST mjRefresh TEST mjRefresh TEST"} + + ) + }; }; ``` @@ -102,6 +119,17 @@ export const MjRefreshDemo = () => { 首先需要使用 DevEco Studio 打开项目里的鸿蒙工程 `harmony` +### 在工程根目录的 `oh-package.json` 添加 overrides字段 + +```json +{ + ... + "overrides": { + "@rnoh/react-native-openharmony" : "./react_native_openharmony" + } +} +``` + ### 引入原生端代码 目前有两种方法: @@ -202,6 +230,7 @@ std::vector> PackageProvider::getPackages(Package::Cont ``` ### 在 ArkTs 侧引入 MJRefresh组件 +使用arkTs版本MjRefresh,需要在buildCustomComponent注册。 找到 **function buildCustomComponent()**,一般位于 `entry/src/main/ets/pages/index.ets` 或 `entry/src/main/ets/rn/LoadBundle.ets`,添加: @@ -265,7 +294,7 @@ ohpm install | onRefreshIdle | System Path | function | No | IOS | yes | | onReleaseToRefresh | System Path | function | No | IOS | yes | | onPulling | System Path | function | No | IOS | yes | - +| HeaderComponent | 设置自定义刷新头 | React.ReactNode | No | No | yes(capi版本支持) | ## 静态方法 > [!tip] "Platform"列表示该属性在原三方库上支持的平台。 @@ -278,6 +307,8 @@ ohpm install | :------------ | ----------- | -------- | -------- | -------- | ----------------- | | beginRefresh | System Path | function | No | IOS | yes | | finishRefresh | System Path | function | No | IOS | yes | +## 遗留问题 + 无 ## 其他