Sfoglia il codice sorgente

Avoid asking for calendar permission on app start

master
zbettenbuk 7 anni fa
parent
commit
7da26042b3

+ 29
- 0
react/features/calendar-sync/components/MeetingList.native.js Vedi File

20
      */
20
      */
21
     dispatch: Function,
21
     dispatch: Function,
22
 
22
 
23
+    /**
24
+     * Tells the component if it's being displayed at the moment, or not.
25
+     * Note: as an example, on Android it can happen that the component
26
+     * is rendered but not displayed, because components like ViewPagerAndroid
27
+     * render their children even if they are not visible at the moment.
28
+     */
29
+    displayed: boolean,
30
+
23
     /**
31
     /**
24
      * The calendar event list.
32
      * The calendar event list.
25
      */
33
      */
35
  * Component to display a list of events from the (mobile) user's calendar.
43
  * Component to display a list of events from the (mobile) user's calendar.
36
  */
44
  */
37
 class MeetingList extends Component<Props> {
45
 class MeetingList extends Component<Props> {
46
+    _initialLoaded: boolean
38
 
47
 
39
     /**
48
     /**
40
      * Default values for the component's props.
49
      * Default values for the component's props.
58
         this._toDateString = this._toDateString.bind(this);
67
         this._toDateString = this._toDateString.bind(this);
59
     }
68
     }
60
 
69
 
70
+    /**
71
+     * Implements React Component's componentWillReceiveProps function.
72
+     *
73
+     * @inheritdoc
74
+     */
75
+    componentWillReceiveProps(newProps) {
76
+        // This is a conditional logic to refresh the calendar entries (thus
77
+        // to request access to calendar) on component first receives a
78
+        // displayed=true prop - to avoid requesting calendar access on
79
+        // app start.
80
+        if (!this._initialLoaded
81
+                && newProps.displayed
82
+                && !this.props.displayed) {
83
+            const { dispatch } = this.props;
84
+
85
+            this._initialLoaded = true;
86
+            dispatch(refreshCalendarEntryList());
87
+        }
88
+    }
89
+
61
     /**
90
     /**
62
      * Implements the React Components's render method.
91
      * Implements the React Components's render method.
63
      *
92
      *

+ 10
- 6
react/features/calendar-sync/middleware.js Vedi File

22
     switch (action.type) {
22
     switch (action.type) {
23
     case APP_WILL_MOUNT:
23
     case APP_WILL_MOUNT:
24
         _ensureDefaultServer(store);
24
         _ensureDefaultServer(store);
25
-        _fetchCalendarEntries(store);
25
+        _fetchCalendarEntries(store, false);
26
         break;
26
         break;
27
     case REFRESH_CALENDAR_ENTRY_LIST:
27
     case REFRESH_CALENDAR_ENTRY_LIST:
28
-        _fetchCalendarEntries(store);
28
+        _fetchCalendarEntries(store, true);
29
         break;
29
         break;
30
     case SET_ROOM:
30
     case SET_ROOM:
31
         _parseAndAddDomain(store);
31
         _parseAndAddDomain(store);
38
  * Ensures calendar access if possible and resolves the promise if it's granted.
38
  * Ensures calendar access if possible and resolves the promise if it's granted.
39
  *
39
  *
40
  * @private
40
  * @private
41
+ * @param {boolean} promptForPermission - Flag to tell the app if it should
42
+ * prompt for a calendar permission if it wasn't granted yet.
41
  * @returns {Promise}
43
  * @returns {Promise}
42
  */
44
  */
43
-function _ensureCalendarAccess() {
45
+function _ensureCalendarAccess(promptForPermission) {
44
     return new Promise((resolve, reject) => {
46
     return new Promise((resolve, reject) => {
45
         RNCalendarEvents.authorizationStatus()
47
         RNCalendarEvents.authorizationStatus()
46
             .then(status => {
48
             .then(status => {
47
                 if (status === 'authorized') {
49
                 if (status === 'authorized') {
48
                     resolve();
50
                     resolve();
49
-                } else if (status === 'undetermined') {
51
+                } else if (promptForPermission) {
50
                     RNCalendarEvents.authorizeEventStore()
52
                     RNCalendarEvents.authorizeEventStore()
51
                         .then(result => {
53
                         .then(result => {
52
                             if (result === 'authorized') {
54
                             if (result === 'authorized') {
89
  *
91
  *
90
  * @private
92
  * @private
91
  * @param {Object} store - The redux store.
93
  * @param {Object} store - The redux store.
94
+ * @param {boolean} promptForPermission - Flag to tell the app if it should
95
+ * prompt for a calendar permission if it wasn't granted yet.
92
  * @returns {void}
96
  * @returns {void}
93
  */
97
  */
94
-function _fetchCalendarEntries(store) {
95
-    _ensureCalendarAccess()
98
+function _fetchCalendarEntries(store, promptForPermission) {
99
+    _ensureCalendarAccess(promptForPermission)
96
     .then(() => {
100
     .then(() => {
97
         const startDate = new Date();
101
         const startDate = new Date();
98
         const endDate = new Date();
102
         const endDate = new Date();

+ 4
- 1
react/features/welcome/components/PagedList.android.js Vedi File

41
      */
41
      */
42
     render() {
42
     render() {
43
         const { disabled } = this.props;
43
         const { disabled } = this.props;
44
+        const { pageIndex } = this.state;
44
 
45
 
45
         return (
46
         return (
46
             <View
47
             <View
59
                         <RecentList disabled = { disabled } />
60
                         <RecentList disabled = { disabled } />
60
                     </View>
61
                     </View>
61
                     <View key = { 1 }>
62
                     <View key = { 1 }>
62
-                        <MeetingList disabled = { disabled } />
63
+                        <MeetingList
64
+                            disabled = { disabled }
65
+                            displayed = { pageIndex === 1 } />
63
                     </View>
66
                     </View>
64
                 </ViewPagerAndroid>
67
                 </ViewPagerAndroid>
65
                 <View style = { styles.pageIndicatorContainer }>
68
                 <View style = { styles.pageIndicatorContainer }>

+ 3
- 1
react/features/welcome/components/PagedList.ios.js Vedi File

58
                         onPress = { this._onTabSelected(1) }
58
                         onPress = { this._onTabSelected(1) }
59
                         selected = { pageIndex === 1 }
59
                         selected = { pageIndex === 1 }
60
                         title = { t('welcomepage.calendar') } >
60
                         title = { t('welcomepage.calendar') } >
61
-                        <MeetingList disabled = { disabled } />
61
+                        <MeetingList
62
+                            disabled = { disabled }
63
+                            displayed = { pageIndex === 1 } />
62
                     </TabBarIOS.Item>
64
                     </TabBarIOS.Item>
63
                 </TabBarIOS>
65
                 </TabBarIOS>
64
             </View>
66
             </View>

Loading…
Annulla
Salva