Skip to content

Commit c75e241

Browse files
committed
feat: horizontal scroll
1 parent a9c50b2 commit c75e241

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ $ yarn add native-smart-scroll-container
2727

2828
## Options
2929

30+
Component uses ScrollViewProps
31+
32+
## Example
33+
34+
```js
35+
import React from 'react'
36+
import { View } from 'react-native'
37+
import SmartScrollContainer from 'native-smart-scroll-container'
38+
39+
const App = () => {
40+
return (
41+
<SmartScrollContainer>
42+
<View
43+
style={{
44+
height: 1000,
45+
width: 200 /*TODO 700*/,
46+
backgroundColor: 'red',
47+
}}
48+
/>
49+
</SmartScrollContainer>
50+
)
51+
}
52+
```
53+
3054
## License
3155

3256
This project is licensed under the MIT License © 2020-present Jakub Biesiada

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "native-smart-scroll-container",
33
"version": "0.0.0",
4-
"description": "",
4+
"description": "Enable scroll based on content size",
55
"author": "Jakub Biesiada",
66
"license": "MIT",
77
"main": "lib/index.js",

src/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ const SmartScrollContainer = ({
1010
scrollEnabled,
1111
onLayout,
1212
onContentSizeChange,
13+
horizontal,
1314
}: Props) => {
14-
const [wrapperHeight, setWrapperHeight] = useState(0)
15-
const [contentHeight, setContentHeight] = useState(0)
15+
const [wrapperSize, setWrapperSize] = useState(0)
16+
const [contentSize, setContentSize] = useState(0)
1617

1718
return (
1819
<ScrollView
19-
scrollEnabled={scrollEnabled || wrapperHeight < contentHeight}
20+
horizontal={horizontal}
21+
scrollEnabled={scrollEnabled || wrapperSize < contentSize}
2022
onLayout={(e) => {
21-
setWrapperHeight(e.nativeEvent.layout.height)
23+
setWrapperSize(e.nativeEvent.layout[horizontal ? 'width' : 'height'])
2224

2325
onLayout?.(e)
2426
}}
2527
onContentSizeChange={(w, h) => {
26-
setContentHeight(h)
28+
setContentSize(horizontal ? w : h)
2729

2830
onContentSizeChange?.(w, h)
2931
}}

0 commit comments

Comments
 (0)