Skip to content

Commit 05f5229

Browse files
committed
add support for memoized components
1 parent 5ebc77b commit 05f5229

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

components/Swiper.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import {useWindowDimensions, FlatList, ScrollView, Text, TouchableOpacity, View}
33
import StaticPills from "./StaticPills";
44
import {usePrevious} from "../helpers/usePrevious";
55

6+
const isJSX = element => typeof element?.type === 'object';
7+
const isMemo = element => typeof element?.type === 'function';
8+
69
export default function Swiper({style, data, isStaticPills, initialScrollIndex, ...rest}) {
710
const width = useWindowDimensions().width;
811
const flatList = useRef(null);
@@ -47,8 +50,8 @@ export default function Swiper({style, data, isStaticPills, initialScrollIndex,
4750
});
4851
const renderItem = ({item: {component: Component, props = {}}, index}) => (
4952
<View style={{width}}>
50-
{typeof Component !== 'function' && Component}
51-
{typeof Component === 'function' && <Component {...props} index={index}/>}
53+
{typeof Component !== 'function' && isJSX(Component) && Component}
54+
{typeof Component === 'function' || (typeof Component !== 'function' && isMemo(Component)) && <Component {...props} index={index}/>}
5255
</View>
5356
);
5457

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-screens-swiper",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "This lib. provide swiper view functionality with tab navigation on the top.",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)