-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
1,227 additions
and
371 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
22 changes: 22 additions & 0 deletions
22
demo/src/screens/incubatorScreens/IncubatorCalendarScreen/MockServer.ts
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,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(); |
54 changes: 38 additions & 16 deletions
54
demo/src/screens/incubatorScreens/IncubatorCalendarScreen/index.tsx
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 |
---|---|---|
@@ -1,27 +1,49 @@ | ||
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 | ||
}; | ||
|
||
|
||
componentDidMount(): void { | ||
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> | ||
); | ||
} | ||
} |
Oops, something went wrong.