Skip to content

Commit 1770f08

Browse files
authored
docs:update README.md (#7)
1 parent 27ec9f6 commit 1770f08

File tree

1 file changed

+309
-31
lines changed

1 file changed

+309
-31
lines changed

README.md

Lines changed: 309 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,309 @@
1-
<!--
2-
* @Author: 石破天惊
3-
* @email: shanshang130@gmail.com
4-
* @Date: 2020-11-05 10:44:46
5-
* @LastEditTime: 2021-07-23 23:42:43
6-
* @LastEditors: 石破天惊
7-
* @Description:
8-
-->
9-
**React Native Spring ScrollView**
10-
11-
**React Native Spring ScrollView** is a high performance cross-platform native bounces ScrollView for React Native.(iOS & Android) It is easy to support pulling to refresh and dragging to load more data. It is bridged from Native after V2.
12-
13-
### Features
14-
15-
* High performance cross-platform native bounces ScrollView (iOS & Android)
16-
* Simultaneous gesture on both horizontal and vertical directions.
17-
* Smoothly scroll
18-
* Highly customizing refreshing and loading animation. Fully support `react-native-lottie` process with `useNativeDriver`.
19-
* Solved the common problem of views that need to move out of the way of the virtual keyboard.
20-
* Native onScroll contentOffset on both horizontal and vertical directions
21-
* Resolved no response with onRefresh and onLoading in some special case.
22-
* PagingEnabled on both horizontal and vertical directions.(<font color=red>New</font>)
23-
* Nested self like iOS. (<font color=red>New</font>)
24-
25-
### Documentation
26-
Check out our dedicated documentation page for info about this library, API reference and more:
27-
[Documentation Reference](https://bolan9999.github.io/react-native-spring-scrollview/#/)
28-
29-
30-
### Preview
31-
![Preview](./docs/res/android-test.gif)
1+
<!-- {% raw %} -->
2+
> 模板版本:v0.2.2
3+
4+
<p align="center">
5+
<h1 align="center">react-native-spring-scrollview</code> </h1>
6+
</p>
7+
<p align="center">
8+
<a href="https://github.com/bolan9999/react-native-spring-scrollview">
9+
<img src="https://img.shields.io/badge/platforms-android%20|%20ios%20|%20harmony%20-lightgrey.svg" alt="Supported platforms" />
10+
</a>
11+
<a href="https://github.com/bolan9999/react-native-spring-scrollview/blob/master/LICENSE>">
12+
<img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License" />
13+
</a>
14+
</p>
15+
16+
> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-spring-scrollview)
17+
18+
## 安装与使用
19+
20+
请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-oh-tpl/react-native-spring-scrollview Releases](https://github.com/react-native-oh-library/react-native-spring-scrollview/releases),并下载适用版本的 tgz 包。
21+
22+
进入到工程目录并输入以下命令:
23+
24+
> [!TIP] # 处替换为 tgz 包的路径
25+
26+
<!-- tabs:start -->
27+
28+
#### **npm**
29+
30+
```bash
31+
npm install @react-native-oh-tpl/react-native-spring-scrollview@file:#
32+
```
33+
34+
#### **yarn**
35+
36+
```bash
37+
yarn add @react-native-oh-tpl/react-native-spring-scrollview@file:#
38+
```
39+
40+
<!-- tabs:end -->
41+
42+
下面的代码展示了这个库的基本使用场景:
43+
44+
> [!WARNING] 使用时 import 的库名不变。
45+
46+
```js
47+
import React from 'react';
48+
import {
49+
StyleSheet,
50+
Text,
51+
TouchableOpacity,
52+
View,
53+
Platform,
54+
Animated,
55+
ScrollView,
56+
} from 'react-native';
57+
import {SpringScrollView} from 'react-native-spring-scrollview';
58+
59+
const AnimatedSpringScrollView = Animated.createAnimatedComponent(SpringScrollView);
60+
export default class ScrollToAndOnScrollExample extends React.Component {
61+
_contentCount = 20;
62+
_scrollView;
63+
_nativeOffset = {
64+
y: new Animated.Value(0),
65+
};
66+
67+
render() {
68+
const arr = [];
69+
for (let i = 0; i < this._contentCount; ++i) arr.push(i);
70+
return (
71+
<View style={styles.container}>
72+
<TouchableOpacity style={styles.scrollTo} onPress={this._scrollTo}>
73+
<Text>Tap to ScrollTo y=200</Text>
74+
</TouchableOpacity>
75+
<SpringScrollView
76+
style={styles.container}
77+
ref={(ref) => (this._scrollView = ref)}
78+
onTouchBegin={this._onTouchBegin}
79+
onTouchFinish={this._onTouchEnd}
80+
onMomentumScrollBegin={this.onMomentumScrollBegin}
81+
onMomentumScrollEnd={this._onMomentumScrollEnd}
82+
onNativeContentOffsetExtract={this._nativeOffset}
83+
>
84+
{arr.map((i, index) => (
85+
<Text key={index} style={styles.text}>
86+
Scroll and Look up the console log to check if
87+
'onScroll','onTouchBegin','onTouchEnd','onMomentumScrollBegin' and
88+
'onMomentumScrollEnd' work well!
89+
</Text>
90+
))}
91+
<Animated.View style={this._stickyHeaderStyle}>
92+
<Text>Test `onNativeContentOffsetExtract`</Text>
93+
</Animated.View>
94+
</SpringScrollView>
95+
</View>
96+
);
97+
}
98+
```
99+
100+
## Link
101+
102+
目前HarmonyOS暂不支持 AutoLink,所以 Link 步骤需要手动配置。
103+
104+
首先需要使用 DevEco Studio 打开项目里的HarmonyOS工程 `harmony`
105+
106+
本库HarmonyOS侧实现依赖@react-native-oh-tpl/lottie-react-native的原生端代码,如已在HarmonyOS工程中引入过该库,则无需再次引入,可跳过本章步骤,直接使用。
107+
108+
如为引入请参考[@react-native-oh-tpl/lottie-react-native文档的link章节](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/lottie-react-native.md#link)进行引入
109+
110+
### 在工程根目录的 `oh-package.json` 添加 overrides 字段
111+
112+
```json
113+
{
114+
...
115+
"overrides": {
116+
"@rnoh/react-native-openharmony" : "./react_native_openharmony"
117+
}
118+
}
119+
```
120+
121+
### 引入原生端代码
122+
123+
目前有两种方法:
124+
125+
1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
126+
2. 直接链接源码。
127+
128+
方法一:通过 har 包引入(推荐)
129+
130+
> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。
131+
132+
打开 `entry/oh-package.json5`,添加以下依赖
133+
134+
```json
135+
"dependencies": {
136+
"@rnoh/react-native-openharmony": "file:../react_native_openharmony",
137+
"@react-native-oh-tpl/react-native-spring-scrollview": "file:../../node_modules/@react-native-oh-tpl/react-native-spring-scrollview/harmony/spring-scrollview.har",
138+
}
139+
```
140+
141+
点击右上角的 `sync` 按钮
142+
143+
或者在终端执行:
144+
145+
```bash
146+
cd entry
147+
ohpm install
148+
```
149+
150+
方法二:直接链接源码
151+
152+
> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md)
153+
154+
### 配置 CMakeLists 和引入 SpringScrollViewPackge
155+
156+
打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
157+
158+
```diff
159+
project(rnapp)
160+
cmake_minimum_required(VERSION 3.4.1)
161+
set(CMAKE_SKIP_BUILD_RPATH TRUE)
162+
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
163+
set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
164+
+ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
165+
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
166+
set(LOG_VERBOSITY_LEVEL 1)
167+
set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
168+
set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
169+
set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
170+
add_compile_definitions(WITH_HITRACE_SYSTRACE)
171+
172+
add_subdirectory("${RNOH_CPP_DIR}" ./rn)
173+
174+
# RNOH_BEGIN: manual_package_linking_1
175+
add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
176+
+ add_subdirectory("${OH_MODULES}/@react-native-oh-tpl/react-native-spring-scrollview/src/main/cpp" ./spring-scrollview)
177+
# RNOH_END: manual_package_linking_1
178+
179+
file(GLOB GENERATED_CPP_FILES "./generated/*.cpp")
180+
181+
add_library(rnoh_app SHARED
182+
${GENERATED_CPP_FILES}
183+
"./PackageProvider.cpp"
184+
"${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
185+
)
186+
target_link_libraries(rnoh_app PUBLIC rnoh)
187+
188+
# RNOH_BEGIN: manual_package_linking_2
189+
target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
190+
+ target_link_libraries(rnoh_app PUBLIC rnoh_spring_scrollview)
191+
# RNOH_END: manual_package_linking_2
192+
```
193+
194+
打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
195+
196+
```diff
197+
#include "RNOH/PackageProvider.h"
198+
#include "generated/RNOHGeneratedPackage.h"
199+
#include "SamplePackage.h"
200+
+ #include "SpringScrollViewPackage.h"
201+
202+
using namespace rnoh;
203+
204+
std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
205+
return {
206+
std::make_shared<RNOHGeneratedPackage>(ctx),
207+
std::make_shared<SamplePackage>(ctx),
208+
+ std::make_shared<SpringScrollViewPackage>(ctx),
209+
};
210+
}
211+
```
212+
213+
### 在 ArkTs 侧引入 SpringScrollViewPackage
214+
215+
打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
216+
217+
```diff
218+
...
219+
+ import {SpringScrollViewPackage} from '@react-native-oh-tpl/react-native-spring-scrollview/ts';
220+
221+
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
222+
return [
223+
new SamplePackage(ctx),
224+
+ new SpringScrollViewPackage(ctx),
225+
];
226+
}
227+
```
228+
229+
打开 `entry/src/main/ets/pages/Index.ets`,添加:
230+
```diff
231+
...
232+
+ const arkTsComponentNames: Array<string> =["SampleView","GeneratedSampleView","PropsDisplayer","LottieAnimationView"];
233+
```
234+
235+
### 运行
236+
237+
点击右上角的 `sync` 按钮
238+
239+
或者在终端执行:
240+
241+
```bash
242+
cd entry
243+
ohpm install
244+
```
245+
246+
然后编译、运行即可。
247+
248+
## 约束与限制
249+
250+
### 兼容性
251+
252+
要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
253+
254+
请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-tpl/react-native-spring-scrollview Releases](https://github.com/react-native-oh-library/react-native-spring-scrollview/releases)
255+
256+
257+
## 属性
258+
259+
> [!tip] "Platform"列表示该属性在原三方库上支持的平台。
260+
261+
> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
262+
263+
| Name | Description | Type | Required | Platform | HarmonyOS Support |
264+
| ---- | ----------- | ---- | -------- | -------- | ------------------ |
265+
| contentStyle | set content style | ViewStyle | yes | iOS/Android | yes |
266+
| bounces | Bounces if the content offset is out of the content view. It won't be bounces on the horizontal direction if the content view is not wider than the wrapper view although bounces is true. But it will on the vertical direction. | boolean | yes | iOS/Android | yes |
267+
| scrollEnabled | scrollEnabled | boolean | yes | iOS/Android | yes |
268+
| directionalLockEnabled | When true, the SpringScrollView will try to lock to only vertical or horizontal scrolling while dragging. | boolean | yes | iOS/Android | yes |
269+
| initialContentOffset | initial content offset. Only works when initiation. | Offset | yes | iOS/Android | yes |
270+
| showsVerticalScrollIndicator | showsVerticalScrollIndicator | boolean | yes | iOS/Android | no |
271+
| showsHorizontalScrollIndicator | showsHorizontalScrollIndicator | boolean | yes | iOS/Android | no |
272+
| refreshHeader | refresh header | React.ComponentClass<RefreshHeaderPropType,RefreshHeaderStateType> | yes | iOS/Android | yes |
273+
| loadingFooter | loading header | React.ComponentClass<LoadingFooterPropType,LoadingFooterStateType> | yes | iOS/Android | yes |
274+
| onRefresh | he callback when refreshing. When this props is configured, a refresh header will be add on the top of the SpringScrollView | ()=>any | yes | iOS/Android | yes |
275+
| onLoading() | The callback of loading. If set this prop, a loading footer will add to the botom of the SpringScrollView | ()=>any | yes | iOS/Android | yes |
276+
| allLoaded | Whether the data is all loaded. | boolean | yes | iOS/Android | yes |
277+
| textInputRefs | text input | any[] | yes | iOS/Android | yes |
278+
| inverted | inverted. It is a service for LargeList. | boolean | yes | iOS/Android | yes |
279+
| inputToolBarHeight | set height of the input toolbar | number | yes | iOS/Android | yes |
280+
| tapToHideKeyboard | hide the currently displayed keyboard | boolean | yes | iOS/Android | yes |
281+
| onTouchBegin() | begin touch | ()=>any | yes | iOS/Android | yes|
282+
| onTouchFinish() | touch finished | ()=>any | yes | iOS/Android | yes|
283+
| beginRefresh() | If you want to begin refreshing programally without finger draging, call this method after initialized. | Promise<any> | yes | iOS/Android | yes|
284+
| endRefresh() | End the refreshing status. | void | yes | iOS/Android | yes|
285+
| endLoading() | End the loading status. | void | yes | iOS/Android | yes|
286+
| scrollTo() | animate scroll to a specific position | Promise<void> | yes | iOS/Android | yes|
287+
| scroll() | scroll animation to a specific position | Promise<void> | yes | iOS/Android | yes|
288+
| scrollToBegin() | scroll begin | Promise<void> | yes | iOS/Android | yes|
289+
| scrollToEnd() | scroll end | Promise<void> | yes | iOS/Android | yes|
290+
| onScroll() | scroll | (evt: ScrollEvent) => any | yes | iOS/Android | yes|
291+
| onNativeContentOffsetExtract | calculate content offset | NativeContentOffset | yes | iOS/Android | yes|
292+
| onScrollBeginDrag() | an event that is triggered when the user starts dragging (scrolling) content. | ()=>any | yes | iOS/Android | yes|
293+
| onMomentumScrollBegin() | When the user scrolls content and the momentum scroll animation begins, it triggers an event. | ()=>any | yes | iOS/Android | yes|
294+
| onMomentumScrollEnd() | When the user scrolls content and the momentum scroll animation ends, it triggers an event. | ()=>any | yes | iOS/Android | yes|
295+
| onSizeChange | The callback when the wrapper view size changed. | (size: Size) => any | yes | iOS/Android | yes |
296+
| onContentSizeChange | The callback when the content view size changed. | (size: Size) => any | yes | iOS/Android | yes |
297+
298+
## 遗留问题
299+
300+
- [ ] showsVerticalScrollIndicator属性harmony暂不支持[issue#3](https://github.com/react-native-oh-library/react-native-spring-scrollview/issues/3)
301+
- [ ] showsHorizontalScrollIndicator属性harmony暂不支持[issue#4](https://github.com/react-native-oh-library/react-native-spring-scrollview/issues/4)
302+
303+
## 其他
304+
305+
## 开源协议
306+
307+
本项目基于 [The MIT License (MIT)](https://github.com/bolan9999/react-native-spring-scrollview/blob/master/LICENSE) ,请自由地享受和参与开源。
308+
309+
<!-- {% endraw %} -->

0 commit comments

Comments
 (0)