diff --git a/react/features/calendar-sync/components/MeetingList.native.js b/react/features/calendar-sync/components/MeetingList.native.js index 4875e194e..6de63937a 100644 --- a/react/features/calendar-sync/components/MeetingList.native.js +++ b/react/features/calendar-sync/components/MeetingList.native.js @@ -20,6 +20,14 @@ type Props = { */ dispatch: Function, + /** + * Tells the component if it's being displayed at the moment, or not. + * Note: as an example, on Android it can happen that the component + * is rendered but not displayed, because components like ViewPagerAndroid + * render their children even if they are not visible at the moment. + */ + displayed: boolean, + /** * The calendar event list. */ @@ -35,6 +43,7 @@ type Props = { * Component to display a list of events from the (mobile) user's calendar. */ class MeetingList extends Component { + _initialLoaded: boolean /** * Default values for the component's props. @@ -58,6 +67,26 @@ class MeetingList extends Component { this._toDateString = this._toDateString.bind(this); } + /** + * Implements React Component's componentWillReceiveProps function. + * + * @inheritdoc + */ + componentWillReceiveProps(newProps) { + // This is a conditional logic to refresh the calendar entries (thus + // to request access to calendar) on component first receives a + // displayed=true prop - to avoid requesting calendar access on + // app start. + if (!this._initialLoaded + && newProps.displayed + && !this.props.displayed) { + const { dispatch } = this.props; + + this._initialLoaded = true; + dispatch(refreshCalendarEntryList()); + } + } + /** * Implements the React Components's render method. * diff --git a/react/features/calendar-sync/middleware.js b/react/features/calendar-sync/middleware.js index bf601ca21..150cd129a 100644 --- a/react/features/calendar-sync/middleware.js +++ b/react/features/calendar-sync/middleware.js @@ -22,10 +22,10 @@ MiddlewareRegistry.register(store => next => action => { switch (action.type) { case APP_WILL_MOUNT: _ensureDefaultServer(store); - _fetchCalendarEntries(store); + _fetchCalendarEntries(store, false); break; case REFRESH_CALENDAR_ENTRY_LIST: - _fetchCalendarEntries(store); + _fetchCalendarEntries(store, true); break; case SET_ROOM: _parseAndAddDomain(store); @@ -38,15 +38,17 @@ MiddlewareRegistry.register(store => next => action => { * Ensures calendar access if possible and resolves the promise if it's granted. * * @private + * @param {boolean} promptForPermission - Flag to tell the app if it should + * prompt for a calendar permission if it wasn't granted yet. * @returns {Promise} */ -function _ensureCalendarAccess() { +function _ensureCalendarAccess(promptForPermission) { return new Promise((resolve, reject) => { RNCalendarEvents.authorizationStatus() .then(status => { if (status === 'authorized') { resolve(); - } else if (status === 'undetermined') { + } else if (promptForPermission) { RNCalendarEvents.authorizeEventStore() .then(result => { if (result === 'authorized') { @@ -89,10 +91,12 @@ function _ensureDefaultServer(store) { * * @private * @param {Object} store - The redux store. + * @param {boolean} promptForPermission - Flag to tell the app if it should + * prompt for a calendar permission if it wasn't granted yet. * @returns {void} */ -function _fetchCalendarEntries(store) { - _ensureCalendarAccess() +function _fetchCalendarEntries(store, promptForPermission) { + _ensureCalendarAccess(promptForPermission) .then(() => { const startDate = new Date(); const endDate = new Date(); diff --git a/react/features/welcome/components/PagedList.android.js b/react/features/welcome/components/PagedList.android.js index 6db6cbf2b..c1e7db560 100644 --- a/react/features/welcome/components/PagedList.android.js +++ b/react/features/welcome/components/PagedList.android.js @@ -41,6 +41,7 @@ export default class PagedList extends AbstractPagedList { */ render() { const { disabled } = this.props; + const { pageIndex } = this.state; return ( - + diff --git a/react/features/welcome/components/PagedList.ios.js b/react/features/welcome/components/PagedList.ios.js index e65a6826a..6779985c8 100644 --- a/react/features/welcome/components/PagedList.ios.js +++ b/react/features/welcome/components/PagedList.ios.js @@ -58,7 +58,9 @@ class PagedList extends AbstractPagedList { onPress = { this._onTabSelected(1) } selected = { pageIndex === 1 } title = { t('welcomepage.calendar') } > - +