From dcd9b0a52864f0aabc3e574bf730392bdcb5fb44 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 5 Jun 2024 08:44:33 +0300 Subject: [PATCH] use togglebutton component --- src/components/forms/ToggleButton.tsx | 2 +- src/view/com/composer/labels/LabelsBtn.tsx | 95 +++++++++++----------- 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/src/components/forms/ToggleButton.tsx b/src/components/forms/ToggleButton.tsx index f47a272b18..8e08665fde 100644 --- a/src/components/forms/ToggleButton.tsx +++ b/src/components/forms/ToggleButton.tsx @@ -36,7 +36,7 @@ export function Group({children, multiple, ...props}: GroupProps) { export function Button({children, ...props}: ItemProps) { return ( - + {children} ) diff --git a/src/view/com/composer/labels/LabelsBtn.tsx b/src/view/com/composer/labels/LabelsBtn.tsx index e557848bb2..f5caadc70d 100644 --- a/src/view/com/composer/labels/LabelsBtn.tsx +++ b/src/view/com/composer/labels/LabelsBtn.tsx @@ -1,5 +1,5 @@ import React from 'react' -import {Keyboard, View} from 'react-native' +import {Keyboard, LayoutAnimation, View} from 'react-native' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -8,9 +8,9 @@ import {isNative} from '#/platform/detection' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' +import * as ToggleButton from '#/components/forms/ToggleButton' import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' import {Text} from '#/components/Typography' -import {SelectableBtn} from '../../util/forms/SelectableBtn' const ADULT_CONTENT_LABELS = ['sexual', 'nudity', 'porn'] @@ -27,16 +27,10 @@ export function LabelsBtn({ const t = useTheme() const {_} = useLingui() - const toggleAdultLabel = (label: string) => { - const hadLabel = labels.includes(label) - const stripped = labels.filter(l => !ADULT_CONTENT_LABELS.includes(l)) - const final = !hadLabel ? stripped.concat([label]) : stripped - onChange(final) - } - const removeAdultLabel = () => { const final = labels.filter(l => !ADULT_CONTENT_LABELS.includes(l)) onChange(final) + LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) } const hasAdultSelection = @@ -44,6 +38,10 @@ export function LabelsBtn({ labels.includes('nudity') || labels.includes('porn') + if (!hasMedia && hasAdultSelection) { + removeAdultLabel() + } + return ( <> - ) : null} + + {hasMedia ? ( <> - - toggleAdultLabel('sexual')} - accessibilityHint="" - style={a.flex_1} - /> - toggleAdultLabel('nudity')} - accessibilityHint="" - style={a.flex_1} - /> - toggleAdultLabel('porn')} - accessibilityHint="" - style={a.flex_1} - /> - + { + onChange(values) + LayoutAnimation.configureNext( + LayoutAnimation.Presets.easeInEaseOut, + ) + }}> + + + Suggestive + + + + + Nudity + + + + + Porn + + + {labels.includes('sexual') ? (