File tree Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Original file line number Diff line number Diff 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
3256This project is licensed under the MIT License © 2020-present Jakub Biesiada
Original file line number Diff line number Diff line change 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" 
Original file line number Diff line number Diff 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      } } 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments