@@ -43,7 +43,8 @@ type Props = ReactProps & DefaultProps
4343
4444type State = {
4545 filters : Array < FilterType > ,
46- } ;
46+ cachedFoodItems : ?MenuItemContainerType ,
47+ }
4748
4849const styles = StyleSheet . create ( {
4950 inner : {
@@ -64,16 +65,26 @@ export class FancyMenu extends React.Component<Props, State> {
6465
6566 state = {
6667 filters : [ ] ,
68+ cachedFoodItems : null ,
6769 }
6870
69- static getDerivedStateFromProps ( props : Props ) {
70- let { foodItems , menuCorIcons, meals, now} = props
71- let filters = buildFilters ( values ( foodItems ) , menuCorIcons , meals , now )
72- return { filters }
71+ static getDerivedStateFromProps ( props : Props , prevState : State ) {
72+ // we only need to do this when the menu has changed; this avoids
73+ // us overriding our changes from FilterView.onDismiss
74+ if (
75+ ! prevState . cachedFoodItems ||
76+ props . foodItems === prevState . cachedFoodItems
77+ ) {
78+ let { foodItems, menuCorIcons, meals, now} = props
79+ let filters = buildFilters ( values ( foodItems ) , menuCorIcons , meals , now )
80+ return { filters, cachedFoodItems : props . foodItems }
81+ }
82+ return null
7383 }
7484
7585 areSpecialsFiltered = ( filters : Array < FilterType > ) =>
7686 Boolean ( filters . find ( this . isSpecialsFilter ) )
87+
7788 isSpecialsFilter = ( f : FilterType ) =>
7889 f . enabled && f . type === 'toggle' && f . spec . label === 'Only Show Specials'
7990
0 commit comments