diff --git a/native/components/color-rows.react.js b/native/components/color-rows.react.js new file mode 100644 index 000000000..50aaf4953 --- /dev/null +++ b/native/components/color-rows.react.js @@ -0,0 +1,57 @@ +// @flow + +import * as React from 'react'; +import { View, StyleSheet } from 'react-native'; + +import { selectedThreadColors } from 'lib/shared/color-utils.js'; +import type { SetState } from 'lib/types/hook-types.js'; + +import ColorSelectorButton from './color-selector-button.react.js'; + +type Props = { + +pendingColor: string, + +setPendingColor: SetState, +}; + +function ColorRows(props: Props): React.Node { + const { pendingColor, setPendingColor } = props; + + const colorSelectorButtons = React.useMemo( + () => + selectedThreadColors.map(color => ( + + )), + [pendingColor, setPendingColor], + ); + + const firstRow = React.useMemo( + () => colorSelectorButtons.slice(0, colorSelectorButtons.length / 2), + [colorSelectorButtons], + ); + + const secondRow = React.useMemo( + () => colorSelectorButtons.slice(colorSelectorButtons.length / 2), + [colorSelectorButtons], + ); + + return ( + <> + {firstRow} + {secondRow} + + ); +} + +const styles = StyleSheet.create({ + colorRowContainer: { + flexDirection: 'row', + justifyContent: 'space-evenly', + }, +}); + +export default ColorRows; diff --git a/native/components/color-selector.react.js b/native/components/color-selector.react.js index 1134c54c2..c2d3b2dce 100644 --- a/native/components/color-selector.react.js +++ b/native/components/color-selector.react.js @@ -1,105 +1,78 @@ // @flow import * as React from 'react'; import { Text, TouchableOpacity, View } from 'react-native'; import tinycolor from 'tinycolor2'; -import { selectedThreadColors } from 'lib/shared/color-utils.js'; - -import ColorSelectorButton from './color-selector-button.react.js'; +import ColorRows from './color-rows.react.js'; import { useStyles } from '../themes/colors.js'; type ColorSelectorProps = { +currentColor: string, +windowWidth: number, +onColorSelected: (hex: string) => void, }; function ColorSelector(props: ColorSelectorProps): React.Node { const { currentColor, onColorSelected } = props; const [pendingColor, setPendingColor] = React.useState(currentColor); const styles = useStyles(unboundStyles); - const colorSelectorButtons = React.useMemo( - () => - selectedThreadColors.map(color => ( - - )), - [pendingColor], - ); - - const firstRow = React.useMemo( - () => colorSelectorButtons.slice(0, colorSelectorButtons.length / 2), - [colorSelectorButtons], - ); - - const secondRow = React.useMemo( - () => colorSelectorButtons.slice(colorSelectorButtons.length / 2), - [colorSelectorButtons], - ); - const saveButtonDisabled = tinycolor.equals(currentColor, pendingColor); const saveButtonStyle = React.useMemo( () => [ styles.saveButton, { backgroundColor: saveButtonDisabled ? '#404040' : `#${pendingColor}`, width: 0.75 * props.windowWidth, }, ], [styles.saveButton, saveButtonDisabled, pendingColor, props.windowWidth], ); const onColorSplotchSaved = React.useCallback(() => { onColorSelected(`#${pendingColor}`); }, [onColorSelected, pendingColor]); return ( Select chat color - {firstRow} - {secondRow} + Save ); } const unboundStyles = { - colorButtons: { - flexDirection: 'row', - justifyContent: 'space-evenly', - }, container: { alignItems: 'center', flex: 1, }, header: { color: 'modalForegroundLabel', fontSize: 24, fontWeight: 'bold', marginBottom: 10, marginTop: 20, }, saveButton: { alignItems: 'center', borderRadius: 5, margin: 10, padding: 10, }, saveButtonText: { color: 'white', fontSize: 16, }, }; export default ColorSelector;