Skip to content

Commit ba25a3a

Browse files
committed
replace Dimensions.get('window') with useWindowDimensions() hook
1 parent 1bb8d66 commit ba25a3a

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

components/StaticPills.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import React from 'react';
2-
import {Dimensions, Text, TouchableOpacity, View} from "react-native";
2+
import {useWindowDimensions, Text, TouchableOpacity, View} from "react-native";
33
import {getOpacity} from "../helpers/getOpacity";
44

5-
const width = Dimensions.get('window').width;
6-
75
export default function StaticPills({data, style, x, currentIndex, onPillPress}) {
6+
const width = useWindowDimensions().width;
87
return (
98
<View style={styles.container}>
109
{!!data?.length && data.map((item, index) => (
1110
<View key={index}>
12-
<TouchableOpacity key={index} onPress={onPillPress(index)} style={[
11+
<TouchableOpacity onPress={onPillPress(index)} style={[
1312
{
1413
paddingHorizontal: 5,
15-
width: width / data.length - 20,
14+
width: width / data.length,
1615
alignItems: 'center',
1716
},
1817
style?.pillButton,
@@ -26,8 +25,9 @@ export default function StaticPills({data, style, x, currentIndex, onPillPress})
2625
</TouchableOpacity>
2726
<View style={[
2827
{
28+
marginTop: 5,
2929
marginHorizontal: 10,
30-
borderColor: 'white',
30+
borderColor: 'red',
3131
borderBottomWidth: 2,
3232
// for fade in and fade out animation
3333
opacity: getOpacity(index, x),
@@ -44,7 +44,6 @@ const styles = {
4444
container: {
4545
flexDirection: 'row',
4646
justifyContent: 'space-around',
47-
width: width - 20,
4847
paddingBottom: 8,
4948
},
5049
pillLabel: {
@@ -54,8 +53,4 @@ const styles = {
5453
color: 'red',
5554
marginBottom: 10,
5655
},
57-
activeBorder: {
58-
borderColor: 'red',
59-
borderBottomWidth: 2,
60-
},
6156
};

components/Swiper.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React, {useRef, useState} from "react";
2-
import {Dimensions, FlatList, ScrollView, Text, TouchableOpacity, View} from "react-native";
2+
import {useWindowDimensions, FlatList, ScrollView, Text, TouchableOpacity, View} from "react-native";
33
import StaticPills from "./StaticPills";
44
import {usePrevious} from "../helpers/usePrevious";
55

6-
const width = Dimensions.get('window').width;
7-
86
export default function Swiper({style, data, isStaticPills, ...rest}) {
7+
const width = useWindowDimensions().width;
98
const flatList = useRef(null);
109
const scrollViewRef = useRef(null);
1110
const buttonRef = useRef(null);

0 commit comments

Comments
 (0)