diff --git a/native/components/color-selector-button.react.js b/native/components/color-selector-button.react.js --- a/native/components/color-selector-button.react.js +++ b/native/components/color-selector-button.react.js @@ -4,22 +4,31 @@ import { StyleSheet, TouchableOpacity, View } from 'react-native'; import tinycolor from 'tinycolor2'; +import type { SetState } from 'lib/types/hook-types'; + type ColorSelectorButtonProps = { +color: string, - +currentColor: string, + +pendingColor: string, + +setPendingColor: SetState, }; - function ColorSelectorButton(props: ColorSelectorButtonProps): React.Node { - const { color, currentColor } = props; + const { color, pendingColor, setPendingColor } = props; const colorSplotchStyle = React.useMemo(() => { return [styles.button, { backgroundColor: `#${color}` }]; }, [color]); - const isSelected = tinycolor.equals(currentColor, color); + const onPendingColorSelected = React.useCallback(() => { + setPendingColor(color); + }, [setPendingColor, color]); + + const isSelected = tinycolor.equals(pendingColor, color); return ( - + ); } diff --git a/native/components/color-selector.react.js b/native/components/color-selector.react.js --- a/native/components/color-selector.react.js +++ b/native/components/color-selector.react.js @@ -1,7 +1,8 @@ // @flow import * as React from 'react'; -import { Text, View, StyleSheet } from 'react-native'; +import { Button, Text, View, StyleSheet } from 'react-native'; +import tinycolor from 'tinycolor2'; import { selectedThreadColors } from 'lib/shared/thread-utils'; @@ -9,10 +10,11 @@ type ColorSelectorProps = { +currentColor: string, + +onColorSelected: (hex: string) => void, }; - function ColorSelector(props: ColorSelectorProps): React.Node { - const { currentColor } = props; + const { currentColor, onColorSelected } = props; + const [pendingColor, setPendingColor] = React.useState(currentColor); const colorSelectorButtons = React.useMemo( () => @@ -20,26 +22,44 @@ )), - [currentColor], + [pendingColor], + ); + + const saveButtonDisabled = tinycolor.equals(currentColor, pendingColor); + const saveButtonStyle = React.useMemo( + () => [ + styles.saveButton, + { backgroundColor: saveButtonDisabled ? '#404040' : `#${pendingColor}` }, + ], + [saveButtonDisabled, pendingColor], ); + const onColorSplotchSaved = React.useCallback(() => { + onColorSelected(`#${pendingColor}`); + }, [onColorSelected, pendingColor]); + return ( - - Select thread color - + Select thread color {colorSelectorButtons} + +