Browse Source

Fix for theme not updating

Arnaud Vergnet 4 years ago
parent
commit
9bdfe3944e

+ 38
- 25
src/components/Custom/CustomAgenda.js View File

@@ -1,46 +1,59 @@
1 1
 import * as React from 'react';
2
+import {View} from "react-native";
2 3
 import {withTheme} from 'react-native-paper';
3 4
 import {Agenda} from "react-native-calendars";
4 5
 
6
+type Props = {
7
+    theme: Object,
8
+}
9
+
5 10
 /**
6 11
  * Abstraction layer for Agenda component, using custom configuration
7
- *
8
- * @param props Props to pass to the element. Must specify an onRef prop to get an Agenda ref.
9
- * @return {*}
10 12
  */
11
-function CustomAgenda(props) {
12
-    const {colors} = props.theme;
13
-    return (
14
-        <Agenda
15
-            {...props}
16
-            ref={props.onRef}
13
+class CustomAgenda extends React.Component<Props> {
14
+
15
+    getAgenda() {
16
+        return <Agenda
17
+            {...this.props}
18
+            ref={this.props.onRef}
17 19
             theme={{
18
-                backgroundColor: colors.agendaBackgroundColor,
19
-                calendarBackground: colors.background,
20
-                textSectionTitleColor: colors.agendaDayTextColor,
21
-                selectedDayBackgroundColor: colors.primary,
20
+                backgroundColor: this.props.theme.colors.agendaBackgroundColor,
21
+                calendarBackground: this.props.theme.colors.background,
22
+                textSectionTitleColor: this.props.theme.colors.agendaDayTextColor,
23
+                selectedDayBackgroundColor: this.props.theme.colors.primary,
22 24
                 selectedDayTextColor: '#ffffff',
23
-                todayTextColor: colors.primary,
24
-                dayTextColor: colors.text,
25
-                textDisabledColor: colors.agendaDayTextColor,
26
-                dotColor: colors.primary,
25
+                todayTextColor: this.props.theme.colors.primary,
26
+                dayTextColor: this.props.theme.colors.text,
27
+                textDisabledColor: this.props.theme.colors.agendaDayTextColor,
28
+                dotColor: this.props.theme.colors.primary,
27 29
                 selectedDotColor: '#ffffff',
28 30
                 arrowColor: 'orange',
29
-                monthTextColor: colors.primary,
30
-                indicatorColor: colors.primary,
31
+                monthTextColor: this.props.theme.colors.primary,
32
+                indicatorColor: this.props.theme.colors.primary,
31 33
                 textDayFontWeight: '300',
32 34
                 textMonthFontWeight: 'bold',
33 35
                 textDayHeaderFontWeight: '300',
34 36
                 textDayFontSize: 16,
35 37
                 textMonthFontSize: 16,
36 38
                 textDayHeaderFontSize: 16,
37
-                agendaDayTextColor: colors.agendaDayTextColor,
38
-                agendaDayNumColor: colors.agendaDayTextColor,
39
-                agendaTodayColor: colors.primary,
40
-                agendaKnobColor: colors.primary,
39
+                agendaDayTextColor: this.props.theme.colors.agendaDayTextColor,
40
+                agendaDayNumColor: this.props.theme.colors.agendaDayTextColor,
41
+                agendaTodayColor: this.props.theme.colors.primary,
42
+                agendaKnobColor: this.props.theme.colors.primary,
41 43
             }}
42
-        />
43
-    );
44
+        />;
45
+    }
46
+
47
+    render() {
48
+        if (this.props.theme.colors.text === "#ffffff") // We are in light mode
49
+            return (
50
+                <View style={{flex: 1}}>
51
+                    {this.getAgenda()}
52
+                </View>
53
+            );
54
+        else
55
+            return this.getAgenda();
56
+    }
44 57
 }
45 58
 
46 59
 export default withTheme(CustomAgenda);

+ 8
- 1
src/screens/Planning/PlanningScreen.js View File

@@ -40,7 +40,7 @@ const AGENDA_MONTH_SPAN = 3;
40 40
 /**
41 41
  * Class defining the app's planning screen
42 42
  */
43
-export default class PlanningScreen extends React.Component<Props, State> {
43
+class PlanningScreen extends React.Component<Props, State> {
44 44
 
45 45
     agendaRef: Object;
46 46
 
@@ -226,10 +226,15 @@ export default class PlanningScreen extends React.Component<Props, State> {
226 226
         );
227 227
     }
228 228
 
229
+    componentDidUpdate(prevProps: Props, prevState: State, prevContext: *): * {
230
+        console.log('coucou');
231
+    }
232
+
229 233
     render() {
230 234
         // console.log("rendering PlanningScreen");
231 235
         return (
232 236
             <CustomAgenda
237
+                {...this.props}
233 238
                 // the list of items that have to be displayed in agenda. If you want to render item as empty date
234 239
                 // the value of date key kas to be an empty array []. If there exists no value for date key it is
235 240
                 // considered that the date in question is not yet loaded
@@ -259,3 +264,5 @@ export default class PlanningScreen extends React.Component<Props, State> {
259 264
         );
260 265
     }
261 266
 }
267
+
268
+export default PlanningScreen;

+ 7
- 16
src/screens/Proximo/ProximoListScreen.js View File

@@ -4,9 +4,10 @@ import * as React from 'react';
4 4
 import {FlatList, Image, Platform, ScrollView, View} from "react-native";
5 5
 import i18n from "i18n-js";
6 6
 import CustomModal from "../../components/Custom/CustomModal";
7
-import {IconButton, RadioButton, Searchbar, Subheading, Text, Title, withTheme} from "react-native-paper";
7
+import {RadioButton, Searchbar, Subheading, Text, Title, withTheme} from "react-native-paper";
8 8
 import {stringMatchQuery} from "../../utils/Search";
9 9
 import ProximoListItem from "../../components/Lists/ProximoListItem";
10
+import HeaderButton from "../../components/Custom/HeaderButton";
10 11
 
11 12
 function sortPrice(a, b) {
12 13
     return a.price - b.price;
@@ -37,6 +38,7 @@ const LIST_ITEM_HEIGHT = 84;
37 38
 type Props = {
38 39
     navigation: Object,
39 40
     route: Object,
41
+    theme: Object,
40 42
 }
41 43
 
42 44
 type State = {
@@ -54,8 +56,6 @@ class ProximoListScreen extends React.Component<Props, State> {
54 56
     listData: Array<Object>;
55 57
     shouldFocusSearchBar: boolean;
56 58
 
57
-    colors: Object;
58
-
59 59
     constructor(props) {
60 60
         super(props);
61 61
         this.listData = this.props.route.params['data']['data'];
@@ -65,8 +65,6 @@ class ProximoListScreen extends React.Component<Props, State> {
65 65
             currentSortMode: 3,
66 66
             modalCurrentDisplayItem: null,
67 67
         };
68
-
69
-        this.colors = props.theme.colors;
70 68
     }
71 69
 
72 70
 
@@ -104,14 +102,7 @@ class ProximoListScreen extends React.Component<Props, State> {
104 102
      * @return {*}
105 103
      */
106 104
     getSortMenuButton = () => {
107
-        return (
108
-            <IconButton
109
-                icon="sort"
110
-                color={this.colors.text}
111
-                size={26}
112
-                onPress={this.onSortMenuPress}
113
-            />
114
-        );
105
+        return <HeaderButton icon="sort" onPress={this.onSortMenuPress}/>;
115 106
     };
116 107
 
117 108
     /**
@@ -164,11 +155,11 @@ class ProximoListScreen extends React.Component<Props, State> {
164 155
     getStockColor(availableStock: number) {
165 156
         let color: string;
166 157
         if (availableStock > 3)
167
-            color = this.colors.success;
158
+            color = this.props.theme.colors.success;
168 159
         else if (availableStock > 0)
169
-            color = this.colors.warning;
160
+            color = this.props.theme.colors.warning;
170 161
         else
171
-            color = this.colors.danger;
162
+            color = this.props.theme.colors.danger;
172 163
         return color;
173 164
     }
174 165
 

Loading…
Cancel
Save