diff --git a/native/chat/settings/color-picker-modal.react.js b/native/chat/settings/color-picker-modal.react.js --- a/native/chat/settings/color-picker-modal.react.js +++ b/native/chat/settings/color-picker-modal.react.js @@ -55,7 +55,7 @@ const { color, threadInfo } = this.props.route.params; // Based on the assumption we are always in portrait, // and consequently width is the lowest dimensions - const modalStyle = { height: this.props.windowWidth - 5 }; + const modalStyle = { height: this.props.windowWidth - 100 }; return ( string) | string) => void, }; - 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,43 @@ )), - [currentColor], + [pendingColor], ); + const saveButtonDisabled = tinycolor.equals(currentColor, pendingColor); + const saveButtonStyle = React.useMemo(() => { + if (saveButtonDisabled) { + return [styles.saveButton, { backgroundColor: '#404040' }]; + } + return [styles.saveButton, { backgroundColor: `#${pendingColor}` }]; + }, [saveButtonDisabled, pendingColor]); + + const onColorSplotchSelected = React.useCallback(() => { + onColorSelected(`#${pendingColor}`); + }, [onColorSelected, pendingColor]); + return ( - - Select thread color - + Select thread color {colorSelectorButtons} + +