From 7850e97b860b152fc5b96dc0258e59e6259ab93f Mon Sep 17 00:00:00 2001
From: huangzongzheng <1518931313@qq.com>
Date: Thu, 12 Sep 2024 16:47:57 +0800
Subject: [PATCH] =?UTF-8?q?docs:=20[Issue:=20#IAQW8R]=E4=BF=AE=E6=94=B9rea?=
=?UTF-8?q?ct-native-swiper=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
zh-cn/react-native-swiper.md | 491 ++++++++++++++++++++++-------------
1 file changed, 314 insertions(+), 177 deletions(-)
diff --git a/zh-cn/react-native-swiper.md b/zh-cn/react-native-swiper.md
index 243cc561..8c24f40b 100644
--- a/zh-cn/react-native-swiper.md
+++ b/zh-cn/react-native-swiper.md
@@ -1,235 +1,372 @@
-
> 模板版本:v0.2.2
-
react-native-swiper
+ react-native-ezswiper
-
-
+
+
-
+
-
-> [!tip] [Github 地址](https://github.com/leecade/react-native-swiper)
+> [!Tip] [Github 地址](https://github.com/easyui/react-native-ezswiper)
## 安装与使用
+进入到工程目录并输入以下命令:
+
#### **npm**
```bash
-npm i react-native-swiper@1.6.0 --save
+npm install react-native-ezswiper@1.3.0 --save
```
#### **yarn**
```bash
-yarn add react-native-swiper@1.6.0
+yarn add react-native-ezswiper@1.3.0 --save
```
-快速使用:
+下面的代码展示了这个库的基本使用场景:
```js
-import React, { Component } from "react";
-import { AppRegistry, StyleSheet, Text, View } from "react-native";
+/**
+ * Sample React Native App
+ * https://github.com/facebook/react-native
+ * @flow
+ */
+
+import React, { Component } from 'react';
+import {
+ StyleSheet,
+ Text,
+ Button,
+ View,
+ Dimensions,
+ ScrollView,
+ SafeAreaView,
+ Image
+} from 'react-native';
+
+const { width } = Dimensions.get('window');
+import EZSwiper from 'react-native-ezswiper';
+
+export default class ezswiperApp extends Component<{}> {
+ constructor(props) {
+ super(props)
+ this.state = {
+ currentPage: 0,
+ };
+ }
+
+ renderTitle(title) {
+ return {title}
+ }
+
+ renderRow(obj, index) {
+ return (
+
+ {obj}
+
+ )
+ }
+
+ renderImageRow(obj, index) {
+ return (
+
+
+ {'Victoria\'s Secre ' + index}
+
+
+ )
+ }
+
+
+ onPressRow(obj, index) {
+ console.log('onPressRow=>obj:' + obj + ' ,index:' + index);
+ alert('onPressRow=>obj:' + obj + ' ,index:' + index);
+ }
+
+ onWillChange(obj, index) {
+ console.log('onWillChange=>obj:' + obj + ' ,index:' + index);
+ }
+
+ onDidChange(obj, index, setDidChangeObj, setIndex) {
+ setDidChangeObj(obj);
+ setIndex(index)
+ }
+
+ render() {
+
+ return (
+
+
+
+ card:ratio 0.6
+
+
+
+ left
+
+
+
+ right
+
+
+
+ normal
+
+
+
+ card ratio:0.867 loop:false index:2
+
+
+
+
+
+ card ratio:0.867 horizontal:false
+
+
+
+
+
+
+
+
+ );
+ }
+}
+
+
+const DidChangeDom = (props) => {
+ const [didChangeObj, setDidChangeObj] = React.useState(0);
+ const [index, setIndex] = React.useState(0);
+
+ return (
+
+
+ obj:{didChangeObj} index:{index}
+
+ {
+ setDidChangeObj(obj)
+ setIndex(index)
+ }} />
+ )
+}
+
+const WillChangeDom = (props) => {
+ const [didChangeObj, setDidChangeObj] = React.useState(0);
+ const [index, setIndex] = React.useState(0);
+
+ return (
+
+
+ obj:{didChangeObj} index:{index}
+
+ {
+ setDidChangeObj(obj)
+ setIndex(index)
+ }} />
+ )
+}
+
+function ScrollToDom(props) {
+ this.refDom = null;
+ const refDomFn = (view) => {
+ this.refDom = view
+ }
+ const scrollTo = (index) => {
+ if (this.refDom) {
+ this.refDom.scrollTo(index + 1, true)
+ }
+ }
+ return (
+
+
+
+
+ )
+}
-import Swiper from "react-native-swiper";
const styles = StyleSheet.create({
- wrapper: {},
- slide1: {
+ container: {
flex: 1,
- justifyContent: "center",
- alignItems: "center",
- backgroundColor: "#9DD6EB",
+ backgroundColor: 'white',
},
- slide2: {
- flex: 1,
- justifyContent: "center",
- alignItems: "center",
- backgroundColor: "#97CAE5",
+ swiper: {
+ backgroundColor: 'white'
},
- slide3: {
+ button: {
+ width: 50,
+ height: 30,
+ },
+ cell: {
+ backgroundColor: 'red',
flex: 1,
- justifyContent: "center",
- alignItems: "center",
- backgroundColor: "#92BBD9",
+ alignItems: 'center',
+ justifyContent: 'center',
},
- text: {
- color: "#fff",
- fontSize: 30,
- fontWeight: "bold",
+ pageControl: {
+ position: 'absolute',
+ bottom: 4,
+ right: 10,
},
+ tips:{
+ backgroundColor:'green'
+ }
});
+```
-export default class SwiperComponent extends Component {
- render() {
- return (
-
-
- Hello Swiper
-
-
- Beautiful
-
-
- And simple
-
-
- );
- }
-}
-AppRegistry.registerComponent("myproject", () => SwiperComponent);
-```
## 约束与限制
-### 兼容性
+## 兼容性
-在以下版本验证通过
+本文档内容基于以下版本验证通过:
-1. RNOH:0.72.13; SDK:HarmonyOS NEXT Developer Preview1; IDE:DevEco Studio 4.1.3.500; ROM:2.0.0.58;
+1.RNOH: 0.72.29; SDK:HarmonyOS-Next-DB1 5.0.0.61; IDE:DevEco Studio 5.0.3.706; ROM:5.0.0.61;
## 属性
-> [!tip] "Platform"列表示该属性在原三方库上支持的平台。
-
-> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
-
-#### basics
-
-| Name | Description | Type | Default | platform | HarmonyOS Support |
-| :------------- | ------------------------------------------------------------ | :------: | :-------------: | -------- | ----------------- |
-| horizontal | If `true`, the scroll view's children are arranged horizontally in a row instead of vertically in a column. | `bool` | true | All | YES |
-| loop | Set to `false` to disable continuous loop mode. | `bool` | true | All | YES |
-| index | Index number of initial slide. | `number` | 0 | All | YES |
-| showsButtons | Set to `true` make control buttons visible. | `bool` | false | All | YES |
-| autoplay | Set to `true` enable auto play mode. | `bool` | false | All | YES |
-| onIndexChanged | Called with the new index when the user swiped | `func` | (index) => null | All | YES |
-
-#### Custom basic style & content
-
-| Name | Description | Type | Default | platform | HarmonyOS Support |
-| :---------------- | :----------------------------------------------------------- | :-------: | :---------------------: | -------- | ----------------- |
-| width | If no specify default enable fullscreen mode by `flex: 1`. | `number` | - | All | YES |
-| height | If no specify default fullscreen mode by `flex: 1`. | `number` | - | All | YES |
-| style | See default style in source. | `style` | {...} | All | YES |
-| containerStyle | See default container style in source. | `style` | {...} | All | YES |
-| loadMinimal | Only load current index slide , `loadMinimalSize` slides before and after. | `bool` | false | All | YES |
-| loadMinimalSize | see `loadMinimal` | `number` | 1 | All | YES |
-| loadMinimalLoader | Custom loader to display when slides aren't loaded | `element` | `` | All | YES |
-
-#### Pagination
-
-| Name | Description | Type | Default | platform | HarmonyOS Support |
-| :--------------- | :----------------------------------------------------------- | :--------: | :----------------------------------------------------------: | -------- | ----------------- |
-| showsPagination | Set to `true` make pagination visible. | `bool` | true | All | YES |
-| paginationStyle | Custom styles will merge with the default styles. | `style` | {...} | All | YES |
-| renderPagination | Complete control how to render pagination with three params (`index`, `total`, `context`) ref to `this.state.index` / `this.state.total` / `this`, For example: show numbers instead of dots. | `function` | - | All | YES |
-| dot | Allow custom the dot element. | `element` | `` | All | YES |
-| activeDot | Allow custom the active-dot element. | `element` | `` | All | YES |
-| dotStyle | Allow custom the dot element. | `object` | - | All | YES |
-| dotColor | Allow custom the dot element. | `string` | - | All | YES |
-| activeDotColor | Allow custom the active-dot element. | `string` | - | All | YES |
-| activeDotStyle | Allow custom the active-dot element. | `object` | - | All | YES |
-
-#### Autoplay
-
-| Name | Description | Type | Default | platform | HarmonyOS Support |
-| :---------------- | :----------------------------------------------- | :------: | :-----: | -------- | ----------------- |
-| autoplay | Set to `true` enable auto play mode. | `bool` | true | All | YES |
-| autoplayTimeout | Delay between auto play transitions (in second). | `number` | 2.5 | All | YES |
-| autoplayDirection | Cycle direction control. | `bool` | true | All | YES |
-
-#### Control buttons
-
-| Prop | Default | Type | Description | platform | HarmonyOS Support | remark |
-| :----------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------: | :------------------------------------------ | -------- | ----------------- | ------ |
-| showsButtons | true | `bool` | Set to `true` make control buttons visible. | All | YES | -- |
-| buttonWrapperStyle | `{backgroundColor: 'transparent', flexDirection: 'row', position: 'absolute', top: 0, left: 0, flex: 1, paddingHorizontal: 10, paddingVertical: 10, justifyContent: 'space-between', alignItems: 'center'}` | `style` | Custom styles. | All | YES | -- |
-| nextButton | `›` | `element` | Allow custom the next button. | All | YES | -- |
-| prevButton | `‹` | `element` | Allow custom the prev button. | All | YES | -- |
-
-#### Props of Children
-
-| Name | Description | Type | Default | platform | HarmonyOS Support |
-| :---- | :----------------------------------------------------------- | :-------: | :----------------------------------: | -------- | ----------------- |
-| style | Custom styles will merge with the default styles. | `style` | {...} | All | YES |
-| title | If this parameter is not specified, will not render the title. | `element` | {...} | All | YES |
-
-#### Basic props of ``
-
-| Name | Description | Type | Default | platform | HarmonyOS Support | remark |
-| :------------------------------- | :----------------------------------------------------------- | :----: | :-----: | -------- | ----------------- | ------------------------------------------------------------ |
-| horizontal | If `true`, the scroll view's children are arranged horizontally in a row instead of vertically in a column. | `bool` | true | All | YES | -- |
-| pagingEnabled | If true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for horizontal pagination. | `bool` | true | All | YES | -- |
-| showsHorizontalScrollIndicator | Set to `true` if you want to show horizontal scroll bar. | `bool` | false | All | YES | -- |
-| showsVerticalScrollIndicator | Set to `true` if you want to show vertical scroll bar. | `bool` | false | All | YES | -- |
-| bounces | If `true`, the scroll view bounces when it reaches the end of the content if the content is larger then the scroll view along the axis of the scroll direction. If `false`, it disables all bouncing even if the alwaysBounce\* props are true. | `bool` | false | All | YES | -- |
-| scrollsToTop | If true, the scroll view scrolls to top when the status bar is tapped. | `bool` | false | All | NO | 组件属性继承RNOH scrollview,当前RNOH中的scrollsToTop暂时不支持 |
-| removeClippedSubviews | If true, offscreen child views (whose overflow value is hidden) are removed from their native backing superview when offscreen. This canimprove scrolling performance on long lists. | `bool` | true | All | NO | 组件属性继承RNOH scrollview,当前RNOH中的removeClippedSubviews暂时不支持 |
-| automaticallyAdjustContentInsets | Set to `true` if you need adjust content insets automation. | `bool` | false | All | NO | 组件属性继承RNOH scrollview,当前RNOH中的automaticallyAdjustContentInsets暂时不支持 |
-| scrollEnabled | Enables/Disables swiping | `bool` | true | All | YES | -- |
-
-> @see: http://facebook.github.io/react-native/docs/scrollview.html
-
-#### Supported ScrollResponder
-
-| Name | Description | Type | Params | platform | HarmonyOS Support |
-| :------------------ | :---------------------------------------------------------- | :--------: | :-----------------------: | -------- | ----------------- |
-| onScrollBeginDrag | When animation begins after letting up | `function` | `e` / `state` / `context` | All | YES |
-| onMomentumScrollEnd | Makes no sense why this occurs first during bounce | `function` | `e` / `state` / `context` | All | YES |
-| onTouchStartCapture | Immediately after `onMomentumScrollEnd` | `function` | `e` / `state` / `context` | All | YES |
-| onTouchStart | Same, but bubble phase | `function` | `e` / `state` / `context` | All | YES |
-| onTouchEnd | You could hold the touch start for a long time | `function` | `e` / `state` / `context` | All | YES |
-| onResponderRelease | When lifting up - you could pause forever before \* lifting | `function` | `e` / `state` / `context` | All | YES |
-
-> Note: each ScrollResponder be injected with two params: `state` and `context`, you can get `state` and `context`(ref to swiper's `this`) from params, for example:
-
-```jsx
-var swiper = React.createClass({
- _onMomentumScrollEnd: function (e, state, context) {
- console.log(state, context.state)
- },
- render: function() {
- return (
-
- )
- }
-})
-```
+> [!Tip] "Platform"列表示该属性在原三方库上支持的平台。
+
+> [!Tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
+
+| Name | Description | Type | default | Required | Platform | HarmonyOS Support |
+| --------------------- | ------------------------------------------------------------------------------------------------------ | -------- | -------- | -------- | ----------------- | ----------------- |
+| `width` | swiper width | number | | Yes | All | yes |
+| `height` | swiper height | number | | Yes | All | yes |
+| `index` | initial index bar. | number | 0 | No | All | yes |
+| `offset` | initial left and right or up and down offsets view. | number | 0 | No | All | yes |
+| `horizontal` | swiper derection is horizontal | boolean | true | No | All | yes |
+| `loop` | swiper is loop | boolean | true | No | All | yes |
+| `autoplayTimeout` | auto play mode (in second) | number | 5 | No | All | yes |
+| `autoplayDirection` | cycle direction control | boolean | true | No | All | yes |
+| `ratio` | scaling ratio | number | 1 | No | All | yes |
+| `cardParams` | swiper card advanced object | object | {} | No | All | yes |
+| `renderRow` | render card view | function | | Yes | All | yes |
+| `onPress` | card is clicked action | function | | No | All | yes |
+| `onWillChange` | next card will show | function | | No | All | yes |
+| `onDidChange` | next card showed | function | | No | All | yes |
-### 方法
+cardParams is object:{cardSide,cardSmallSide,cardSpace}
+
-#### scrollBy(index, animated)
+## 静态方法
-| Name | Description | Type | default | platform | HarmonyOS Support |
-| :------- | :----------- | :------: | :---------: | -------- | ----------------- |
-| index | offset index | `number` | `undefined` | All | YES |
-| animated | offset index | `bool` | `true` | All | YES |
+> [!Tip] "Platform"列表示该属性在原三方库上支持的平台。
-### 遗留问题
+> [!Tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
-- [ ] 组件属性继承RNOH scrollview,当前RNOH中的scrollsToTop暂时不支持
-- [ ] 组件属性继承RNOH scrollview,当前RNOH中的removeClippedSubviews暂时不支持
-- [ ] 组件属性继承RNOH scrollview,当前RNOH中的automaticallyAdjustContentInsets暂时不支持
-- [ ] 组件轮播图RNOH版本为0.72.13暂时有不居中问题,在RNOH版本为0.72.19上解决
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+| --------------------- | ------------------------------------------------------------------------------------------------------ | -------- | -------- | -------- | ----------------- |
+| `scrollTo(index, animated = true)` | scroll to position | function | No | All | yes |
-### 其他
+## 遗留问题
-### 开源协议
+## 其他
-本项目基于 [The MIT License (MIT)](https://github.com/leecade/react-native-swiper/blob/master/LICENSE) ,请自由地享受和参与开源。
+## 开源协议
-
\ No newline at end of file
+本项目基于 [The MIT License (MIT)](https://github.com/easyui/react-native-ezswiper) ,请自由地享受和参与开源。
--
Gitee