Skip to content

Commit

Permalink
docs: updated flatlist implementation info
Browse files Browse the repository at this point in the history
  • Loading branch information
pwysowski committed Aug 5, 2020
1 parent 7bbe85c commit f4d77f4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ Below are examples of those components and description of the props they are acc

[Custom header props and example](docs/CUSTOM.md)

## Handling nested scrollables

[Handling nested flatlist props and example](docs/CUSTOM.md#Tips)


<h1 id="Getting-Started">Getting Started</h1>

## Prerequisites
Expand Down
56 changes: 54 additions & 2 deletions docs/CUSTOM.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
| `header` | `ReactElement` | Yes | - | This renders header component |
| `initialPage` | `number` | No | `0` | Set initial page of tab bar |
| `onChangeTab` | `({ i, ref, from }: { from: number; i: number; ref: any; }) => void;` | No | - | Tab change event |
| `onEndReached` | `() => void` | No | - | Tab change event |
| `onEndReached` | `() => void` | No | - | Reached end event
| `onTopReached` | `() => void` | No | - | Reached top event |
| `parallaxHeight` | `number` | No | `0` | Sets height of opened header |
| `scrollEvent` | `(event: NativeSyntheticEvent<NativeScrollEvent>) => void` | No | - | Returns offset of header to apply custom animations |
| `snapStartThreshold` | `number` | No | - | Set start value Threshold of snap |
Expand Down Expand Up @@ -185,4 +186,55 @@ class TabScreen extends React.Component {
```

## Tips
In order to nest scrollable component use `scrollEnabled={false}` on it and move all the logic to the header eg. by using `onEndReached` prop.
In order to nest scrollable component use `scrollEnabled={false}` on it and move all the logic to the header eg. by using `onEndReached` and `onTopReached` props. You can find example in CardScreen.js it's really basic so probably you will want to extend it somehow:

```jsx

shouldBeEnabled = () => {
const {
endReached,
stickyHeaderEndReached,
topReached,
stickyHeaderTopReached
} = this.state
const bottomCondition =
endReached && stickyHeaderEndReached
const topCondition =
topReached && stickyHeaderTopReached
return bottomCondition || topCondition
}

onScroll = ({nativeEvent}) => {
const {contentOffset, layoutMeasurement, contentSize} = nativeEvent;
if (layoutMeasurement.height + contentOffset.y >= contentSize.height - 20) {
this.setState({endReached: true, topReached: false})
}

if (contentOffset.y <= 0) {
this.setState({topReached: true, endReached: false})
}
}

renderFlatlistContent = (user) => (
<View style={styles.flatlistContainer}>
<FlatList
data={user.cards}
renderItem={({item, index}) => (
<QuizCard
data={item}
num={index}
key={item.question}
cardsAmount={100}
/>
)}
onScroll={this.onScroll}
scrollEnabled={
Platform.OS === 'android' ? true : this.shouldBeEnabled()
}
nestedScrollEnabled
/>
</View>
)
```


0 comments on commit f4d77f4

Please sign in to comment.