From c522a410abece0d38525a383a2ae69e3c4823f8c Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Fri, 7 Aug 2020 13:34:39 +0200 Subject: [PATCH] Improve favorite buttons --- .../Lists/PlanexGroups/GroupListItem.js | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/components/Lists/PlanexGroups/GroupListItem.js b/src/components/Lists/PlanexGroups/GroupListItem.js index d8f9db1..72bf957 100644 --- a/src/components/Lists/PlanexGroups/GroupListItem.js +++ b/src/components/Lists/PlanexGroups/GroupListItem.js @@ -1,8 +1,9 @@ // @flow import * as React from 'react'; -import {IconButton, List, withTheme} from 'react-native-paper'; +import {List, TouchableRipple, withTheme} from 'react-native-paper'; import * as Animatable from 'react-native-animatable'; +import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; import type {CustomThemeType} from '../../../managers/ThemeManager'; import type {PlanexGroupType} from '../../../screens/Planex/GroupSelectionScreen'; import type {ListIconPropsType} from '../../../constants/PaperStyles'; @@ -21,7 +22,7 @@ const REPLACE_REGEX = /_/g; class GroupListItem extends React.Component { isFav: boolean; - starRef = {current: null | IconButton}; + starRef: null | Animatable.View; constructor(props: PropsType) { super(props); @@ -38,6 +39,16 @@ class GroupListItem extends React.Component { return shouldUpdate; } + onStarPress = () => { + const {props} = this; + const ref = this.starRef; + if (ref != null) { + if (this.isFav) ref.rubberBand(); + else ref.swing(); + } + props.onStarPress(); + }; + isGroupInFavorites(favorites: Array): boolean { const {item} = this.props; for (let i = 0; i < favorites.length; i += 1) { @@ -46,15 +57,6 @@ class GroupListItem extends React.Component { return false; } - onStarPress = () => { - const {props} = this; - if (this.starRef.current != null) { - if (this.isFav) this.starRef.current.rubberBand(); - else this.starRef.current.swing(); - } - props.onStarPress(); - }; - render(): React.Node { const {props} = this; const {colors} = props.theme; @@ -69,14 +71,27 @@ class GroupListItem extends React.Component { icon="chevron-right" /> )} - right={({size, color}: {size: number, color: string}): React.Node => ( - - ( + { + this.starRef = ref; + }} + useNativeDriver> + + style={{ + marginRight: 10, + marginLeft: 'auto', + marginTop: 'auto', + marginBottom: 'auto', + }}> + + )} style={{