-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: fix package dependency definition * feat: draft js lazy view renderer * fix: excessive renders when wrapped as animated component * fix: reduce likelihood of becoming stuck on fast paging with small buffer * chore: add lazy pager example * docs: change wording Co-authored-by: troZee <12766071+troZee@users.noreply.github.com> Co-authored-by: troZee <12766071+troZee@users.noreply.github.com>
- Loading branch information
Showing
19 changed files
with
486 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react'; | ||
import { Image, StyleSheet, View, SafeAreaView, Animated } from 'react-native'; | ||
|
||
import { LazyPagerView } from 'react-native-pager-view'; | ||
|
||
import { LikeCount } from './component/LikeCount'; | ||
import { NavigationPanel } from './component/NavigationPanel'; | ||
import { useNavigationPanel } from './hook/useNavigationPanel'; | ||
import type { CreatePage } from './utils'; | ||
|
||
const AnimatedPagerView = Animated.createAnimatedComponent(LazyPagerView); | ||
|
||
function keyExtractor(page: CreatePage) { | ||
return `${page.key}`; | ||
} | ||
|
||
function renderItem({ item }: { item: CreatePage }) { | ||
return ( | ||
<View style={item.style}> | ||
<Image style={styles.image} source={item.imgSource} /> | ||
<LikeCount /> | ||
</View> | ||
); | ||
} | ||
|
||
export function LazyPagerViewExample() { | ||
const { ref, ...navigationPanel } = useNavigationPanel< | ||
LazyPagerView<unknown> | ||
>(); | ||
|
||
return ( | ||
<SafeAreaView style={styles.container}> | ||
<AnimatedPagerView | ||
ref={ref} | ||
style={styles.PagerView} | ||
initialPage={0} | ||
overdrag={navigationPanel.overdragEnabled} | ||
scrollEnabled={navigationPanel.scrollEnabled} | ||
onPageScroll={navigationPanel.onPageScroll} | ||
onPageSelected={navigationPanel.onPageSelected} | ||
onPageScrollStateChanged={navigationPanel.onPageScrollStateChanged} | ||
pageMargin={10} | ||
// Lib does not support dynamically orientation change | ||
orientation="horizontal" | ||
// Lib does not support dynamically transitionStyle change | ||
transitionStyle="scroll" | ||
showPageIndicator={navigationPanel.dotsEnabled} | ||
data={navigationPanel.pages} | ||
keyExtractor={keyExtractor} | ||
renderItem={renderItem} | ||
/> | ||
<NavigationPanel {...navigationPanel} /> | ||
</SafeAreaView> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: 'white', | ||
}, | ||
image: { | ||
width: 300, | ||
height: 200, | ||
padding: 20, | ||
}, | ||
PagerView: { | ||
flex: 1, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.