From 9bdfe3944eba986cb02a7b4c01af3f526c14191e Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Thu, 9 Apr 2020 23:30:42 +0200 Subject: [PATCH] Fix for theme not updating --- src/components/Custom/CustomAgenda.js | 63 ++++++++++++++---------- src/screens/Planning/PlanningScreen.js | 9 +++- src/screens/Proximo/ProximoListScreen.js | 23 +++------ 3 files changed, 53 insertions(+), 42 deletions(-) diff --git a/src/components/Custom/CustomAgenda.js b/src/components/Custom/CustomAgenda.js index 8c0f1cd..3d9d15f 100644 --- a/src/components/Custom/CustomAgenda.js +++ b/src/components/Custom/CustomAgenda.js @@ -1,46 +1,59 @@ import * as React from 'react'; +import {View} from "react-native"; import {withTheme} from 'react-native-paper'; import {Agenda} from "react-native-calendars"; +type Props = { + theme: Object, +} + /** * Abstraction layer for Agenda component, using custom configuration - * - * @param props Props to pass to the element. Must specify an onRef prop to get an Agenda ref. - * @return {*} */ -function CustomAgenda(props) { - const {colors} = props.theme; - return ( - { + + getAgenda() { + return - ); + />; + } + + render() { + if (this.props.theme.colors.text === "#ffffff") // We are in light mode + return ( + + {this.getAgenda()} + + ); + else + return this.getAgenda(); + } } export default withTheme(CustomAgenda); diff --git a/src/screens/Planning/PlanningScreen.js b/src/screens/Planning/PlanningScreen.js index b2c5212..ea3d4fe 100644 --- a/src/screens/Planning/PlanningScreen.js +++ b/src/screens/Planning/PlanningScreen.js @@ -40,7 +40,7 @@ const AGENDA_MONTH_SPAN = 3; /** * Class defining the app's planning screen */ -export default class PlanningScreen extends React.Component { +class PlanningScreen extends React.Component { agendaRef: Object; @@ -226,10 +226,15 @@ export default class PlanningScreen extends React.Component { ); } + componentDidUpdate(prevProps: Props, prevState: State, prevContext: *): * { + console.log('coucou'); + } + render() { // console.log("rendering PlanningScreen"); return ( { ); } } + +export default PlanningScreen; diff --git a/src/screens/Proximo/ProximoListScreen.js b/src/screens/Proximo/ProximoListScreen.js index 91e0dc5..ff0179b 100644 --- a/src/screens/Proximo/ProximoListScreen.js +++ b/src/screens/Proximo/ProximoListScreen.js @@ -4,9 +4,10 @@ import * as React from 'react'; import {FlatList, Image, Platform, ScrollView, View} from "react-native"; import i18n from "i18n-js"; import CustomModal from "../../components/Custom/CustomModal"; -import {IconButton, RadioButton, Searchbar, Subheading, Text, Title, withTheme} from "react-native-paper"; +import {RadioButton, Searchbar, Subheading, Text, Title, withTheme} from "react-native-paper"; import {stringMatchQuery} from "../../utils/Search"; import ProximoListItem from "../../components/Lists/ProximoListItem"; +import HeaderButton from "../../components/Custom/HeaderButton"; function sortPrice(a, b) { return a.price - b.price; @@ -37,6 +38,7 @@ const LIST_ITEM_HEIGHT = 84; type Props = { navigation: Object, route: Object, + theme: Object, } type State = { @@ -54,8 +56,6 @@ class ProximoListScreen extends React.Component { listData: Array; shouldFocusSearchBar: boolean; - colors: Object; - constructor(props) { super(props); this.listData = this.props.route.params['data']['data']; @@ -65,8 +65,6 @@ class ProximoListScreen extends React.Component { currentSortMode: 3, modalCurrentDisplayItem: null, }; - - this.colors = props.theme.colors; } @@ -104,14 +102,7 @@ class ProximoListScreen extends React.Component { * @return {*} */ getSortMenuButton = () => { - return ( - - ); + return ; }; /** @@ -164,11 +155,11 @@ class ProximoListScreen extends React.Component { getStockColor(availableStock: number) { let color: string; if (availableStock > 3) - color = this.colors.success; + color = this.props.theme.colors.success; else if (availableStock > 0) - color = this.colors.warning; + color = this.props.theme.colors.warning; else - color = this.colors.danger; + color = this.props.theme.colors.danger; return color; }