Skip to content

Feat/calendar #2503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 146 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
146f1f4
Initial creation of new calendar component
ethanshar Dec 26, 2022
6eac3be
Push typings
ethanshar Dec 26, 2022
b2b7622
render initial components for example screen
ethanshar Dec 26, 2022
9c53baf
Add DateUtils with stubs
ethanshar Dec 26, 2022
e67dbf5
Add tests for DateUtils
ethanshar Dec 26, 2022
5ee5710
Add stub implementation to getDaysOfWeekNumber
ethanshar Dec 26, 2022
5cc1f05
Day - render day from date
Inbal-Tish Dec 26, 2022
a01b586
Merge branch 'feat/Calendar' of github.com:wix/react-native-ui-lib in…
Inbal-Tish Dec 26, 2022
f30c53b
Basic implementation of getWeekNumbersOfMonth
ethanshar Dec 26, 2022
959a0fe
Install date-fns
ethanshar Dec 26, 2022
550a03a
Basic implementation of Month
ethanshar Dec 26, 2022
9875e29
Add Week
M-i-k-e-l Dec 26, 2022
1b6cc4b
Fix Month component
ethanshar Dec 26, 2022
c3e8190
Change to millis
M-i-k-e-l Dec 26, 2022
7ecf4bf
Add key to week
ethanshar Dec 26, 2022
1b7dd9d
Fix hardcoded month value we pass to Month component
ethanshar Dec 26, 2022
d24f2a0
Add test for invalid month
ethanshar Dec 26, 2022
7108cdf
Render header in calendar item
ethanshar Dec 26, 2022
261c645
Header - render header
Inbal-Tish Dec 26, 2022
6ad966d
Merge branch 'feat/Calendar' of github.com:wix/react-native-ui-lib in…
Inbal-Tish Dec 26, 2022
062ba1f
fix CalendarItem render
Inbal-Tish Dec 26, 2022
e4072bc
Create getDaysOfWeekNumber and dependencies
M-i-k-e-l Jan 4, 2023
851a1f7
radability
ethanshar Jan 4, 2023
6714bc3
Add context provider and change firstDayOfWeek to enum
ethanshar Jan 4, 2023
16fc731
Add date and setDate to context
ethanshar Jan 4, 2023
3c956e6
Add getDateObject worklet
ethanshar Jan 4, 2023
286dd99
Fix calendar context types and add initialDate prop
ethanshar Jan 4, 2023
58b27f9
Basic Agenda
M-i-k-e-l Jan 4, 2023
609ddf0
Header - add months by presing arrow buttons
Inbal-Tish Jan 4, 2023
ff64571
Merge branch 'feat/Calendar' of github.com:wix/react-native-ui-lib in…
Inbal-Tish Jan 4, 2023
3b9702d
Add TODOs
ethanshar Jan 5, 2023
ac3e090
Move FirstDayOfWeek from enum to enum+union and fix tests
M-i-k-e-l Jan 5, 2023
e6b2508
MILLIS to MS
M-i-k-e-l Jan 5, 2023
83b0852
Add mock data (script still needs work) and link (types need work)
M-i-k-e-l Jan 5, 2023
4c870cc
Fix script and types
M-i-k-e-l Jan 6, 2023
3451f4c
addMonth - use Date's setMonth function
Inbal-Tish Jan 8, 2023
c9e6092
Moving 'firstDayOfWeek' to be enum
Inbal-Tish Jan 9, 2023
ac47a51
WeekDaysNames - adding new component to Header
Inbal-Tish Jan 9, 2023
19f9a81
add ts notes
Inbal-Tish Jan 9, 2023
e7f806b
update comment for ts version ^4.3.2
Inbal-Tish Jan 9, 2023
a121b48
Set WeekDaysNames format in Header
Inbal-Tish Jan 9, 2023
84331ac
use FirstDayOfWeek enum
Inbal-Tish Jan 9, 2023
cffcdb6
use 'DayNamesFormat' enum
Inbal-Tish Jan 9, 2023
bef8229
remove console
Inbal-Tish Jan 10, 2023
b76ebac
Day - adding onPress
Inbal-Tish Jan 10, 2023
a911820
add todo
Inbal-Tish Jan 10, 2023
1fe9ba4
Minor fixes and remove todos
ethanshar Jan 10, 2023
bec1f95
Change context's date to selectedDate
ethanshar Jan 10, 2023
b35f196
remove style file
Inbal-Tish Jan 10, 2023
fdb53d2
Merge branch 'feat/Calendar' of github.com:wix/react-native-ui-lib in…
Inbal-Tish Jan 10, 2023
798c7f8
valueOf to getTime
M-i-k-e-l Jan 10, 2023
294e33b
export Event
M-i-k-e-l Jan 10, 2023
2543a10
Day - adding selection
Inbal-Tish Jan 10, 2023
e4e073d
Merge branch 'feat/Calendar' of github.com:wix/react-native-ui-lib in…
Inbal-Tish Jan 10, 2023
1fe9f80
Wrap CalendarItem with FlashList
ethanshar Jan 10, 2023
08f4a04
Agenda - add headers + scroll on date change
M-i-k-e-l Jan 11, 2023
3d0361e
Agenda - set date on scroll
M-i-k-e-l Jan 11, 2023
428b4ca
Fix mock and script
M-i-k-e-l Jan 11, 2023
9d2261f
UI touchups
Inbal-Tish Jan 11, 2023
cc4c2fc
sort imports and add test for 'getMonthForIndex' and adding tests to …
Inbal-Tish Jan 11, 2023
51c5656
Header - small ui changes
Inbal-Tish Jan 12, 2023
1b309ce
Context - adding 'showWeeksNumbers'
Inbal-Tish Jan 12, 2023
aa28da2
fix indentation
Inbal-Tish Jan 12, 2023
c189293
margin
Inbal-Tish Jan 12, 2023
a502404
Add TODOs
M-i-k-e-l Jan 12, 2023
6ef0603
Add flex to day
ethanshar Jan 12, 2023
fa0d695
Day - mark today
Inbal-Tish Jan 17, 2023
eb607f1
Fix FirstDayOfWeek enum and add update sources
ethanshar Jan 17, 2023
f352a54
Adding UpdateSource to setDate calls
Inbal-Tish Jan 17, 2023
32723de
Implement setDate to store lastUpdateSource
ethanshar Jan 17, 2023
7c7508f
dateutils - adding 'isSameMonth'
Inbal-Tish Jan 17, 2023
ca4337d
Add estimatedItemSize prop to FlashLists
ethanshar Jan 17, 2023
20a7515
Update mock data
ethanshar Jan 17, 2023
44d8c29
Fix TS errors
ethanshar Jan 17, 2023
562371d
Context - add updateSource
Inbal-Tish Jan 17, 2023
9554352
fix screen errors
Inbal-Tish Jan 17, 2023
5552cf9
fix updateSource on Context
Inbal-Tish Jan 17, 2023
84ef5fb
fix type
Inbal-Tish Jan 17, 2023
400a014
Calendar - add scrollToIndex on selectedDate change
Inbal-Tish Jan 19, 2023
c9dd43e
Agenda - verify update source and use isSameDay
M-i-k-e-l Jan 25, 2023
1504dd2
Calendar - fix scrollToIndex
Inbal-Tish Jan 25, 2023
2d7e10a
Merge branch 'feat/Calendar' of github.com:wix/react-native-ui-lib in…
Inbal-Tish Jan 25, 2023
76880c4
Agenda initial index
M-i-k-e-l Jan 25, 2023
a509989
isSameMonth - support MonthProps type for params
Inbal-Tish Jan 25, 2023
c862a65
remove synchronous calls to isNumber from a worklet
Inbal-Tish Jan 25, 2023
0f61874
Calendar - add setDate on calendar scroll (by user) to the first of t…
Inbal-Tish Jan 25, 2023
ff81069
Fix getWeekNumbersOfMonth and add missing tests
ethanshar Jan 26, 2023
ea4d07c
Fix typing issues
ethanshar Jan 26, 2023
c9a30e8
fix scrolledByUser.value
Inbal-Tish Jan 26, 2023
c69e9a1
Merge branch 'feat/Calendar' of github.com:wix/react-native-ui-lib in…
Inbal-Tish Jan 26, 2023
cf1c1d8
Calendar - fix scrolledByUser
Inbal-Tish Jan 26, 2023
87e1997
merge fix
Inbal-Tish Jan 26, 2023
1e54efa
shush ts wrannings
Inbal-Tish Jan 26, 2023
3717e13
Add todos
ethanshar Jan 26, 2023
fdfadcc
DateUtils - add 'getNormalizedDate' function
Inbal-Tish Jan 29, 2023
4d33cb4
Change week numbering from ISO to default
M-i-k-e-l Jan 29, 2023
771980c
DateUtils - adding 'isToday' and 'isPastDate'
Inbal-Tish Jan 30, 2023
6c67153
adding assets
Inbal-Tish Jan 31, 2023
7ea4b0a
Agenda - fixed height for items and initialScrollIndex
M-i-k-e-l Jan 31, 2023
a451e3e
TodayButton
Inbal-Tish Jan 31, 2023
6378a60
Update calendars mock data
ethanshar Feb 2, 2023
f872273
Adding 'staticHeader' prop to calendar and passing it on context
Inbal-Tish Feb 2, 2023
f5afe2b
Merge branch 'master' into feat/Calendar
ethanshar Feb 3, 2023
235d608
Fix lint
ethanshar Feb 3, 2023
cd3d345
HeaderHeight to context
Inbal-Tish Feb 5, 2023
1997a69
Utils - use JS Date only inside utils (not as a parameter nor return …
Inbal-Tish Feb 5, 2023
aee98ea
Fix tests and remove getNormalizedDate
ethanshar Feb 7, 2023
927d111
fix lint
Inbal-Tish Feb 7, 2023
5bf37fe
Calendar - setDate when 'initialDate' prop changes
Inbal-Tish Feb 7, 2023
9af9a63
Header - fix arrows
Inbal-Tish Feb 7, 2023
7b17447
fix margins
Inbal-Tish Feb 7, 2023
2db7850
Merge branch 'master' into feat/Calendar
ethanshar Feb 8, 2023
e155a55
DateUtils - add 'getTimestamp' from DateObject
Inbal-Tish Feb 8, 2023
ac9f582
Merge branch 'feat/Calendar' of github.com:wix/react-native-ui-lib in…
Inbal-Tish Feb 8, 2023
0fa04a0
fix extra days text color
Inbal-Tish Feb 8, 2023
49d79a5
Adding 'showExtraDays' prop (currently only controls the text color)
Inbal-Tish Feb 8, 2023
031c76b
Merge branch 'master' into feat/Calendar
ethanshar Feb 14, 2023
2075dc3
re export calendar in incubator
ethanshar Feb 14, 2023
02a5ef2
Use useDidUpdate for setDate coming from props change
ethanshar Feb 14, 2023
1ade24a
Merge branch 'master' into feat/Calendar
ethanshar Feb 16, 2023
1838a90
Fix Android item scroll
M-i-k-e-l Feb 16, 2023
2ca502f
Merge branch 'master' of github.com:wix/react-native-ui-lib into feat…
Inbal-Tish Feb 19, 2023
f02e6c0
Day - fix extra days
Inbal-Tish Feb 20, 2023
008beaf
hide extraDays
Inbal-Tish Feb 22, 2023
3772b34
Day - fix inactive date selected
Inbal-Tish Feb 23, 2023
de48689
fix CalendatItem default height
Inbal-Tish Feb 23, 2023
8872327
Merge branch 'master' of github.com:wix/react-native-ui-lib into feat…
Inbal-Tish Feb 26, 2023
7c5491d
Day - fix today background when inactive
Inbal-Tish Feb 27, 2023
29188d8
Header - arrow press - set day to be the first of the month
Inbal-Tish Feb 27, 2023
5f2d447
demo screen - comment out unused
Inbal-Tish Feb 27, 2023
1093a07
CalendarProcessor - add past and future range and pass date as start …
Inbal-Tish Feb 27, 2023
068c306
DateUtils - add 'addYears' to a given date
Inbal-Tish Feb 27, 2023
d6cb8ed
Day - sync color and backgroundColor animations
Inbal-Tish Feb 27, 2023
f77b1f1
Calendar - add infinite scroll
Inbal-Tish Feb 27, 2023
33a253a
move addPages up
Inbal-Tish Feb 27, 2023
8fc8b09
minor changes
ethanshar Mar 1, 2023
4c59b7b
Merge branch 'master' into feat/Calendar
ethanshar Mar 14, 2023
f342af0
Simple POC for scrollable list with native interactions
ethanshar Mar 14, 2023
23ce096
Add basic implementation of mock server
ethanshar Mar 14, 2023
6f0fb9f
Add mini example of AgendaList with animated scroll handler
ethanshar Mar 19, 2023
483c7a5
Merge branch 'master' of github.com:wix/react-native-ui-lib into feat…
Inbal-Tish Apr 19, 2023
b9cf266
Merge branch 'master' of github.com:wix/react-native-ui-lib into feat…
Inbal-Tish Apr 19, 2023
570d376
revert playgroundScren changes
Inbal-Tish Apr 19, 2023
65eac2e
fix callback
Inbal-Tish Apr 19, 2023
59aa588
typo
Inbal-Tish Apr 19, 2023
3ab3567
UpdateSource should not be optional or undefined
Inbal-Tish Apr 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions demo/src/screens/PlaygroundScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, {Component} from 'react';
import {StyleSheet} from 'react-native';
import {View, Text, Card, TextField, Button} from 'react-native-ui-lib'; //eslint-disable-line

export default class PlaygroundScreen extends Component {
Expand All @@ -19,7 +18,3 @@ export default class PlaygroundScreen extends Component {
);
}
}

const styles = StyleSheet.create({
container: {}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import _ from 'lodash';
import {data} from './MockData';

const PAGE_SIZE = 100;
const FAKE_FETCH_TIME = 1500;

class MockServer {
async getEvents(date: number): Promise<any[]> {
return new Promise(resolve => {
const eventIndexByDate = _.findIndex(data, event => {
return event.start > date;
});

setTimeout(() => {
const newEvents = _.slice(data, eventIndexByDate - PAGE_SIZE / 2, eventIndexByDate + PAGE_SIZE / 2);
resolve(newEvents);
}, FAKE_FETCH_TIME);
});
}
}

export default new MockServer();
55 changes: 39 additions & 16 deletions demo/src/screens/incubatorScreens/IncubatorCalendarScreen/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
import _ from 'lodash';
import React, {Component} from 'react';
import {View, Incubator} from 'react-native-ui-lib';
import {data} from './MockData';
import {Incubator} from 'react-native-ui-lib';
import MockServer from './MockServer';

export default class CalendarScreen extends Component {
// constructor(props) {
// super(props);

// setTimeout(() => {
// this.setState({date: 1676026748000});
// }, 2000);
// }
pageIndex = 0;

state = {
date: undefined
date: new Date().getTime(),
events: [] as any[],
showLoader: false
};


constructor(props: any) {
super(props);
this.loadEvents(this.state.date);
}

loadEvents = async (date: number) => {
this.setState({showLoader: true});
const {events} = this.state;
const newEvents = await MockServer.getEvents(date);
this.pageIndex++;
this.setState({events: _.uniqBy([...events, ...newEvents], e => e.id), showLoader: false});
};

onChangeDate = (date: number) => {
console.log('Date change: ', date);
const {events} = this.state;
if (date < events[0]?.start || date > _.last(events)?.start) {
console.log('Load new events');
this.loadEvents(date);
}
};

onEndReached = (date: number) => {
console.log('Reached End: ', date);
this.loadEvents(date);
};

render() {
const {date, events, showLoader} = this.state;
return (
<View flex>
<Incubator.Calendar data={data} staticHeader initialDate={this.state.date}>
<Incubator.Calendar.Agenda/>
</Incubator.Calendar>
</View>
<Incubator.Calendar data={events} initialDate={date} onChangeDate={this.onChangeDate} staticHeader>
<Incubator.Calendar.Agenda onEndReached={this.onEndReached} showLoader={showLoader}/>
</Incubator.Calendar>
);
}
}
56 changes: 32 additions & 24 deletions src/incubator/Calendar/Agenda.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import React, {useContext, useCallback, useRef} from 'react';
import {ActivityIndicator} from 'react-native';
import {runOnJS, useAnimatedReaction, useSharedValue} from 'react-native-reanimated';
import {FlashListPackage} from 'optionalDeps';
import type {FlashList as FlashListType, ViewToken} from '@shopify/flash-list';
import {BorderRadiuses} from 'style';
import {BorderRadiuses, Colors} from 'style';
import View from '../../components/view';
import Text from '../../components/text';
import {isSameDay, isSameMonth} from './helpers/DateUtils';
import {InternalEvent, Event, DateSectionHeader, UpdateSource} from './types';
import {AgendaProps, InternalEvent, Event, DateSectionHeader, UpdateSource} from './types';
import CalendarContext from './CalendarContext';

const FlashList = FlashListPackage?.FlashList;

// TODO: Fix initial scrolling
function Agenda() {
function Agenda(props: AgendaProps) {
const {onEndReached, showLoader} = props;
const {data, selectedDate, setDate, updateSource} = useContext(CalendarContext);
const flashList = useRef<FlashListType<InternalEvent>>(null);
const closestSectionHeader = useSharedValue<DateSectionHeader | null>(null);
Expand Down Expand Up @@ -48,14 +50,7 @@ function Agenda() {

const renderHeader = useCallback((item: DateSectionHeader) => {
return (
<View
marginB-1
paddingB-4
marginH-10
paddingH-10
height={50}
bottom
>
<View marginB-1 paddingB-4 marginH-10 paddingH-10 height={50} bottom>
<Text>{item.header}</Text>
</View>
);
Expand Down Expand Up @@ -96,7 +91,7 @@ function Agenda() {
return selectedDate.value;
},
(selected, previous) => {
if (updateSource?.value !== UpdateSource.AGENDA_SCROLL) {
if (updateSource.value !== UpdateSource.AGENDA_SCROLL) {
if (
selected !== previous &&
(closestSectionHeader.value?.date === undefined || !isSameDay(selected, closestSectionHeader.value?.date))
Expand Down Expand Up @@ -142,19 +137,32 @@ function Agenda() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const _onEndReached = useCallback(() => {
onEndReached?.(selectedDate.value);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [onEndReached]);

return (
<FlashList
ref={flashList}
estimatedItemSize={52}
data={data}
keyExtractor={keyExtractor}
renderItem={renderItem}
getItemType={getItemType}
onViewableItemsChanged={onViewableItemsChanged}
onMomentumScrollBegin={onMomentumScrollBegin}
onScrollBeginDrag={onScrollBeginDrag}
initialScrollIndex={findClosestDateAfter(selectedDate.value)?.index ?? 0}
/>
<View flex>
<FlashList
ref={flashList}
estimatedItemSize={52}
data={data}
keyExtractor={keyExtractor}
renderItem={renderItem}
getItemType={getItemType}
onViewableItemsChanged={onViewableItemsChanged}
onMomentumScrollBegin={onMomentumScrollBegin}
onScrollBeginDrag={onScrollBeginDrag}
initialScrollIndex={findClosestDateAfter(selectedDate.value)?.index ?? 0}
onEndReached={_onEndReached}
/>
{showLoader && (
<View absF center style={{backgroundColor: Colors.rgba(Colors.grey10, 0.2)}}>
<ActivityIndicator/>
</View>
)}
</View>
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/incubator/Calendar/CalendarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import CalendarContext from './CalendarContext';
import Month from './Month';
import Header from './Header';

const CALENDAR_HEIGHT = 250;

const CALENDAR_HEIGHT = 270;

function CalendarItem(props: CalendarItemProps) {
const {year, month} = props;
Expand All @@ -21,6 +22,7 @@ function CalendarItem(props: CalendarItemProps) {
height: CALENDAR_HEIGHT - (staticHeader ? headerHeight.value : 0)
}
];
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [staticHeader]);

if (month !== undefined) {
Expand All @@ -34,7 +36,7 @@ function CalendarItem(props: CalendarItemProps) {
return null;
}

export default CalendarItem;
export default React.memo(CalendarItem);

const styles = StyleSheet.create({
container: {
Expand Down
61 changes: 36 additions & 25 deletions src/incubator/Calendar/Day.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import isNull from 'lodash/isNull';
import React, {useContext, useCallback} from 'react';
import {StyleSheet} from 'react-native';
import Reanimated, {useSharedValue, useAnimatedStyle, useAnimatedReaction} from 'react-native-reanimated';
import Reanimated, {useSharedValue, useAnimatedStyle, useAnimatedReaction, withTiming} from 'react-native-reanimated';
import {Colors} from 'style';
import View from '../../components/view';
import TouchableOpacity from '../../components/touchableOpacity';
Expand All @@ -11,50 +11,61 @@ import {DayProps, UpdateSource} from './types';
import CalendarContext from './CalendarContext';


const DAY_SIZE = 32;
const SELECTION_SIZE = 24;
const NO_COLOR = Colors.transparent;
const TEXT_COLOR = Colors.$textPrimary;
const TODAY_BACKGROUND_COLOR = Colors.$backgroundPrimaryLight;
const INACTIVE_TODAY_BACKGROUND_COLOR = Colors.$backgroundNeutral;
const SELECTED_BACKGROUND_COLOR = Colors.$backgroundPrimaryHeavy;
const SELECTED_TEXT_COLOR = Colors.$textDefaultLight;
const INACTIVE_TEXT_COLOR = Colors.$textNeutralLight;

const AnimatedText = Reanimated.createAnimatedComponent(Text);

const Day = (props: DayProps) => {
const {date, onPress} = props;
const {selectedDate, setDate} = useContext(CalendarContext);
const {date, onPress, inactive} = props;
const {selectedDate, setDate, showExtraDays} = useContext(CalendarContext);

const shouldMarkSelected = !isNull(date) ? isSameDay(selectedDate.value, date) : false;
const isSelected = useSharedValue(shouldMarkSelected);
const isSelected = useSharedValue(!isNull(date) ? isSameDay(selectedDate.value, date) : false);
const backgroundColor = !isToday(date) ? NO_COLOR :
inactive ? INACTIVE_TODAY_BACKGROUND_COLOR : TODAY_BACKGROUND_COLOR;
const isHidden = !showExtraDays && inactive;

const backgroundColor = isToday(date) ? Colors.$backgroundSuccessHeavy : Colors.transparent;
const textColor = isToday(date) ? Colors.$textDefaultLight : Colors.$backgroundPrimaryHeavy;

const animatedStyles = useAnimatedStyle(() => {
useAnimatedReaction(() => {
return selectedDate.value;
}, (selected) => {
isSelected.value = !inactive && isSameDay(selected, date!);
}, []);

const animatedSelectionStyles = useAnimatedStyle(() => {
return {
backgroundColor: isSelected.value ? Colors.$backgroundPrimaryHeavy : backgroundColor,
color: isSelected.value ? Colors.$textDefaultLight : textColor
backgroundColor: withTiming(isSelected.value ? SELECTED_BACKGROUND_COLOR : backgroundColor, {duration: 100})
};
});

const animatedTextStyles = useAnimatedStyle(() => {
return {
color: isSelected.value ? Colors.$textDefaultLight : textColor
color: withTiming(isSelected.value ?
SELECTED_TEXT_COLOR : inactive ?
showExtraDays ? INACTIVE_TEXT_COLOR : NO_COLOR : TEXT_COLOR, {duration: 100})
};
});

useAnimatedReaction(() => {
return selectedDate.value;
}, (selected) => {
isSelected.value = isSameDay(selected, date!);
}, []);

const _onPress = useCallback(() => {
if (date !== null) {
if (date !== null && !isHidden) {
isSelected.value = true;
setDate(date, UpdateSource.DAY_SELECT);
onPress?.(date);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [date, setDate, onPress]);

const renderDay = () => {
const day = !isNull(date) ? getDayOfDate(date) : '';
return (
<View center>
<View reanimated style={[styles.selection, animatedStyles]}/>
<View reanimated style={[styles.selection, animatedSelectionStyles]}/>
<AnimatedText style={animatedTextStyles}>{day}</AnimatedText>
</View>
);
Expand All @@ -71,13 +82,13 @@ export default Day;

const styles = StyleSheet.create({
dayContainer: {
width: 32,
height: 32
width: DAY_SIZE,
height: DAY_SIZE
},
selection: {
position: 'absolute',
width: 24,
height: 24,
borderRadius: 12
width: SELECTION_SIZE,
height: SELECTION_SIZE,
borderRadius: SELECTION_SIZE / 2
}
});
24 changes: 16 additions & 8 deletions src/incubator/Calendar/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,36 @@ import Reanimated, {useAnimatedProps} from 'react-native-reanimated';
import {Colors, Typography} from 'style';
import View from '../../components/view';
import Button from '../../components/button';
import {getDateObject, addMonths, getMonthForIndex} from './helpers/DateUtils';
import {getDateObject, getMonthForIndex, addMonths, getTimestamp} from './helpers/DateUtils';
import {HeaderProps, DayNamesFormat, UpdateSource} from './types';
import CalendarContext from './CalendarContext';
import WeekDaysNames from './WeekDaysNames';

const AnimatedTextInput = Reanimated.createAnimatedComponent(TextInput);
const WEEK_NUMBER_WIDTH = 30;

const WEEK_NUMBER_WIDTH = 32;
const ARROW_NEXT = require('./assets/arrowNext.png');
const ARROW_BACK = require('./assets/arrowBack.png');

const AnimatedTextInput = Reanimated.createAnimatedComponent(TextInput);

const Header = (props: HeaderProps) => {
const {month, year} = props;
const {selectedDate, setDate, showWeeksNumbers, staticHeader, setHeaderHeight} = useContext(CalendarContext);

const getNewDate = useCallback((count: number) => {
const newDate = addMonths(selectedDate.value, count);
const dateObject = getDateObject(newDate);
return getTimestamp({year: dateObject.year, month: dateObject.month, day: 1});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const onLeftArrowPress = useCallback(() => {
setDate(addMonths(selectedDate.value, -1), UpdateSource.MONTH_ARROW);
}, [selectedDate.value, setDate]);
setDate(getNewDate(-1), UpdateSource.MONTH_ARROW);
}, [setDate, getNewDate]);

const onRightArrowPress = useCallback(() => {
setDate(addMonths(selectedDate.value, 1), UpdateSource.MONTH_ARROW);
}, [selectedDate.value, setDate]);
setDate(getNewDate(1), UpdateSource.MONTH_ARROW);
}, [setDate, getNewDate]);

const animatedProps = useAnimatedProps(() => {
const dateObject = getDateObject(selectedDate.value);
Expand All @@ -38,7 +46,7 @@ const Header = (props: HeaderProps) => {

const onLayout = useCallback((event: LayoutChangeEvent) => {
setHeaderHeight?.(event.nativeEvent.layout.height);
}, []);
}, [setHeaderHeight]);

const renderTitle = () => {
// @ts-expect-error
Expand Down
Loading