Skip to content

Commit 5b74529

Browse files
refactor: rewrite VirtualizedList to ScrollView to prevent calculations
1 parent 27e4cae commit 5b74529

File tree

12 files changed

+2358
-2274
lines changed

12 files changed

+2358
-2274
lines changed

example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project.ext.vectoricons = [
2-
iconFontNames: [ 'MaterialIcons.ttf', 'EvilIcons.ttf' ] // Name of the font files you want to copy
2+
iconFontNames: [ 'MaterialCommunityIcons.ttf'] // Name of the font files you want to copy
33
]
44

55
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

example/src/App.tsx

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Linking,
88
Image,
99
Animated,
10+
// I18nManager,
1011
} from 'react-native';
1112
import {
1213
Title,
@@ -44,6 +45,7 @@ function App({
4445
onToggleDarkMode: () => any;
4546
dark: boolean;
4647
}) {
48+
// I18nManager.forceRTL(true);
4749
const theme = useTheme();
4850
const dateFormatter = new Intl.DateTimeFormat(undefined, {
4951
day: 'numeric',
@@ -257,26 +259,30 @@ function App({
257259
</View>
258260
<Enter />
259261
</Animated.View>
260-
<View style={styles.content}>
261-
<Title>Inside page</Title>
262-
</View>
263-
<Animated.View
264-
style={[
265-
styles.content,
266-
styles.contentShadow,
267-
styles.contentInline,
268-
{ backgroundColor },
269-
]}
270-
>
271-
<DatePickerModalContent
272-
// locale={'en'} optional, default: automatic
273-
mode="range"
274-
onDismiss={onDismissRange}
275-
startDate={range.startDate}
276-
endDate={range.endDate}
277-
onConfirm={onChangeRange}
278-
/>
279-
</Animated.View>
262+
{Platform.OS === 'web' ? (
263+
<>
264+
<View style={styles.content}>
265+
<Title>Inside page</Title>
266+
</View>
267+
<Animated.View
268+
style={[
269+
styles.content,
270+
styles.contentShadow,
271+
styles.contentInline,
272+
{ backgroundColor },
273+
]}
274+
>
275+
<DatePickerModalContent
276+
// locale={'en'} optional, default: automatic
277+
mode="range"
278+
onDismiss={onDismissRange}
279+
startDate={range.startDate}
280+
endDate={range.endDate}
281+
onConfirm={onChangeRange}
282+
/>
283+
</Animated.View>
284+
</>
285+
) : null}
280286
<Enter />
281287
<Enter />
282288
<Enter />
@@ -316,7 +322,7 @@ function App({
316322
mode="single"
317323
visible={singleOpen}
318324
onDismiss={onDismissSingle}
319-
date={undefined}
325+
date={date}
320326
onConfirm={onChangeSingle}
321327
// saveLabel="Save" // optional
322328
// label="Select date" // optional

example/yarn.lock

Lines changed: 1755 additions & 1755 deletions
Large diffs are not rendered by default.

src/Date/Calendar.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { StyleSheet, View } from 'react-native'
44
import Swiper from './Swiper'
55

66
import Month from './Month'
7-
import { areDatesOnSameDay, dateToUnix, DisableWeekDaysType } from './dateUtils'
7+
import {
8+
areDatesOnSameDay,
9+
dateToUnix,
10+
DisableWeekDaysType,
11+
getInitialIndex,
12+
} from './dateUtils'
813

914
import CalendarHeader from './CalendarHeader'
1015
import { useCallback, useMemo } from 'react'
@@ -146,6 +151,7 @@ function Calendar(
146151
return (
147152
<View style={styles.root}>
148153
<Swiper
154+
initialIndex={getInitialIndex(startDate || date)}
149155
selectedYear={selectedYear}
150156
scrollMode={scrollMode}
151157
renderItem={({ index }) => (
@@ -158,7 +164,6 @@ function Calendar(
158164
endDate={endDate}
159165
date={date}
160166
onPressYear={onPressYear}
161-
selectedYear={selectedYear}
162167
selectingYear={selectingYear}
163168
onPressDate={onPressDate}
164169
scrollMode={scrollMode}

src/Date/Day.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { Text, TouchableRipple, useTheme } from 'react-native-paper'
33
import { StyleSheet, View } from 'react-native'
44
import DayRange from './DayRange'
55
import { daySize } from './dateUtils'
6-
import { useTextColorOnPrimary } from '../utils'
76

87
function EmptyDayPure() {
98
return <View style={styles.empty} />
109
}
1110
export const EmptyDay = React.memo(EmptyDayPure)
1211

1312
function Day(props: {
13+
textColorOnPrimary: string
1414
day: number
1515
month: number
1616
year: number
@@ -39,16 +39,21 @@ function Day(props: {
3939
isToday,
4040
disabled,
4141
excluded,
42+
textColorOnPrimary,
4243
} = props
4344
const theme = useTheme()
4445
const onPress = React.useCallback(() => {
4546
onPressDate(new Date(year, month, day))
4647
}, [onPressDate, year, month, day])
47-
const color = useTextColorOnPrimary()
4848

4949
const borderColor =
50-
selected || (inRange && theme.dark) ? color : theme.dark ? '#fff' : '#000'
51-
const textColor = selected || (inRange && theme.dark) ? color : undefined
50+
selected || (inRange && theme.dark)
51+
? textColorOnPrimary
52+
: theme.dark
53+
? '#fff'
54+
: '#000'
55+
const textColor =
56+
selected || (inRange && theme.dark) ? textColorOnPrimary : undefined
5257

5358
return (
5459
<View style={[styles.root, disabled && styles.disabled]}>
@@ -78,6 +83,7 @@ function Day(props: {
7883
<Text
7984
style={[
8085
excluded && styles.excludedText,
86+
// @ts-ignore
8187
textColor && { color: textColor },
8288
]}
8389
selectable={false}

0 commit comments

Comments
 (0)