Template version: v0.2.2
react-native-nested-scroll-view
[!TIP] Github address
Find the matching version information in the release address of a third-party library: @react-native-oh-tpl/react-native-nested-scroll-view Releases.For older versions that are not published to npm, please refer to the installation guide to install the tgz package.
Go to the project directory and execute the following instruction:
npm install @react-native-oh-tpl/react-native-nested-scroll-view
yarn add @react-native-oh-tpl/react-native-nested-scroll-view
The following code shows the basic use scenario of the repository:
[!WARNING] The name of the imported repository remains unchanged.
import React from 'react';
import { View, ScrollView, Text, StyleSheet } from 'react-native';
import NestedScrollView from 'react-native-nested-scroll-view';
const NestedScrollViewExample = () => {
return (
<NestedScrollView style={{ flex: 1 }}>
<ScrollView contentContainerStyle={styles.scrollViewContent}>
{[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((item) => (
<View key={item} style={styles.itemContainer}>
<Text style={styles.itemTitle}>Item {item}</Text>
<ScrollView horizontal showsHorizontalScrollIndicator={false}>
{[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((subItem) => (
<View key={subItem} style={styles.subItem}>
<Text>content {subItem}</Text>
</View>
))}
</ScrollView>
</View>
))}
</ScrollView>
</NestedScrollView>
);
};
const styles = StyleSheet.create({
scrollViewContent: {
paddingVertical: 20,
paddingHorizontal: 10,
},
itemContainer: {
marginBottom: 20,
padding: 10,
backgroundColor: '#f0f0f0',
borderRadius: 10,
},
itemTitle: {
fontSize: 18,
fontWeight: 'bold',
marginBottom: 10,
},
subItem: {
width: 100,
height: 100,
backgroundColor: '#b0e0e6',
justifyContent: 'center',
alignItems: 'center',
marginHorizontal: 5,
},
});
export default NestedScrollViewExample;
Click the sync
button in the upper right corner.
Alternatively, run the following instruction on the terminal:
cd entry
ohpm install
Then build and run the code.
To use this repository, you need to use the correct React-Native and RNOH versions. In addition, you need to use DevEco Studio and the ROM on your phone.
Check the release version information in the release address of the third-party library:@react-native-oh-tpl/react-native-nested-scroll-view Releases
Android的ScrollView并不支持像iOS的ScrollView那样的嵌套滚动,在React Native中直接使用原生的ScrollView实现嵌套滚动时,会出现一些滚动上的问题,例如嵌套滚动不流畅或无法正确响应滚动事件等,因此Android使用react-native-nested-scroll-view来解决嵌套滚动的问题;而iOS使用的是React Native中的ScrollView来实现嵌套滚动,HarmonyOS与iOS保持一致,接受所有React Native ScrollView 组件的Props
[!TIP] The Platform column indicates the platform where the properties are supported in the original third-party library.
[!TIP] If the value of HarmonyOS Support is yes, it means that the HarmonyOS platform supports this property; no means the opposite; partially means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.
Name | Description | Type | Required | Platform | HarmonyOS Support |
---|---|---|---|---|---|
contentContainerStyle | 设置滚动视图内容容器的样式. | ViewStyleProp | no | Android/IOS | yes |
disableIntervalMomentum | 如果为 true,则无论手势有多快,滚动视图都会停止在下一个索引处(相对于释放时的滚动位置) | boolean | no | Android/IOS | yes |
decelerationRate | 设置滚动减速速率。 | ('fast' 或 'normal' 或 number) | no | Android/IOS | yes |
horizontal | 指定滚动视图是否为水平方向,默认为垂直方向。 | boolean | no | Android/IOS | yes |
invertStickyHeaders | 粘性标题是否应粘在 ScrollView 的底部而不是顶部。 | boolean | no | Android/IOS | yes |
keyboardDismissMode | 设置键盘消失模式,可选值为"none"、“interactive"和"on-drag” | string | no | Android/IOS | yes |
keyboardShouldPersistTaps | 设置点击输入框以外的区域时键盘是否消失,可选值为"never"、“always"和"handled” | ('always' 或 'never' 或 'handled' 或 true 或 false) | no | Android/IOS | yes |
onMomentumScrollBegin | 开始惯性滚动时触发的回调函数 | (event: ScrollEvent) => void | no | Android/IOS | yes |
onMomentumScrollEnd | 结束惯性滚动时触发的回调函数 | (event: ScrollEvent) => void | no | Android/IOS | yes |
onScroll | 滚动时触发的回调函数 | (event: ScrollEvent) => void | no | Android/IOS | yes |
onScrollBeginDrag | 开始拖拽滚动视图时触发的回调函数 | (event: ScrollEvent) => void | no | Android/IOS | yes |
onScrollEndDrag | 结束拖拽滚动视图时触发的回调函数 | (event: ScrollEvent) => void | no | Android/IOS | yes |
onContentSizeChange | 当 ScrollView 的可滚动内容视图发生变化时调用,处理函数传递内容宽度和内容高度作为参数 | (contentWidth: number, contentHeight: number) => void | no | Android/IOS | yes |
pagingEnabled | 当值为 true 时,滚动条会停在滚动视图的尺寸的整数倍位置 | boolean | no | Android/IOS | yes |
scrollEnabled | 当值为 false 的时候,内容不能滚动,默认值为 true | boolean | no | Android/IOS | yes |
showsVerticalScrollIndicator | 当此属性为 true 的时候,显示一个垂直方向的滚动条 | boolean | no | Android/IOS | yes |
stickyHeaderIndices | 一个子视图下标的数组,用于决定哪些成员会在滚动之后固定在屏幕顶端 | $ReadOnlyArray | no | Android/IOS | yes |
snapToInterval | 当设置了此属性时,会让滚动视图滚动停止后,停止在snapToInterval的倍数的位置 | number | no | Android/IOS | yes |
snapToOffsets | 会使滚动视图停止在定义的偏移处。这可用于对长度小于滚动视图的各种大小的子项进行分页 | $ReadOnlyArray | no | Android/IOS | yes |
snapToStart | 与 snapToOffsets 结合使用。默认情况下,列表的开头算作捕捉偏移。 | boolean | no | Android/IOS | yes |
snapToEnd | 与 snapToOffsets 结合使用。默认情况下,列表末尾算作捕捉偏移 | boolean | no | Android/IOS | yes |
removeClippedSubviews | 当此属性为 true 时,屏幕之外的子视图(子视图的overflow样式需要设为hidden)会被移除 | boolean | no | Android/IOS | yes |
refreshControl | 用于为 ScrollView 提供下拉刷新功能。只能用于垂直视图,即horizontal不能为true | React. Element | no | Android/IOS | yes |
Android的ScrollView并不支持像iOS的ScrollView那样的嵌套滚动,在React Native中直接使用原生的ScrollView实现嵌套滚动时,会出现一些滚动上的问题,例如嵌套滚动不流畅或无法正确响应滚动事件等,因此Android使用react-native-nested-scroll-view来解决嵌套滚动的问题;而iOS使用的是React Native中的ScrollView来实现嵌套滚动,HarmonyOS与iOS保持一致,接受所有React Native ScrollView 组件的Methods
[!TIP] The Platform column indicates the platform where the properties are supported in the original third-party library.
[!TIP] If the value of HarmonyOS Support is yes, it means that the HarmonyOS platform supports this property; no means the opposite; partially means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.
Name | Description | Type | Required | Platform | HarmonyOS Support |
---|---|---|---|---|---|
scrollTo | 该方法用于滚动到指定位置。可以通过x和y参数指定滚动的偏移量,animated参数用于指定是否使用动画效果。 | function | no | Android/IOS | yes |
scrollToEnd | 该方法用于滚动到内容的末尾。可以通过animated参数指定是否使用动画效果。 | function | no | Android/IOS | yes |
flashScrollIndicators | 该方法用于显示滚动指示器,通常在需要提醒用户可以滚动时使用。 | function | no | Android/IOS | yes |
This project is licensed under The MIT License (MIT).
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。