From b2b7659464cfa46c0c24fcd58da18d6edc5e1841 Mon Sep 17 00:00:00 2001 From: Vali98 Date: Fri, 20 Sep 2024 20:38:22 +0800 Subject: [PATCH] feat: updated new character options to popover --- .../CharacterMenu/CharacterNewMenu.tsx | 147 +++++++++++++----- 1 file changed, 109 insertions(+), 38 deletions(-) diff --git a/app/components/CharacterMenu/CharacterNewMenu.tsx b/app/components/CharacterMenu/CharacterNewMenu.tsx index f72e142..7b7b219 100644 --- a/app/components/CharacterMenu/CharacterNewMenu.tsx +++ b/app/components/CharacterMenu/CharacterNewMenu.tsx @@ -2,22 +2,61 @@ import TextBoxModal from '@components/TextBoxModal' import { FontAwesome } from '@expo/vector-icons' import { Characters, Chats, Logger, Style } from '@globals' import { useRouter } from 'expo-router' -import { useState } from 'react' -import { View, StyleSheet, TouchableOpacity } from 'react-native' +import { useEffect, useRef, useState } from 'react' +import { StyleSheet, TouchableOpacity, Text, BackHandler } from 'react-native' +import { + Menu, + MenuOption, + MenuOptions, + MenuOptionsCustomStyle, + MenuTrigger, + renderers, +} from 'react-native-popup-menu' import Animated, { Easing, SlideInRight, SlideOutRight } from 'react-native-reanimated' import { useShallow } from 'zustand/react/shallow' +const { Popover } = renderers + type CharacterNewMenuProps = { nowLoading: boolean setNowLoading: (b: boolean) => void getCharacterList: () => Promise } +type PopupProps = { + onPress: () => void | Promise + label: string + iconName: 'pencil' | 'cloud-download' | 'upload' +} + +const PopupOption: React.FC = ({ onPress, label, iconName }) => { + return ( + + + + {label} + + + ) +} + const CharacterNewMenu: React.FC = ({ nowLoading, setNowLoading, getCharacterList, }) => { + const menuRef: React.MutableRefObject = useRef(null) + + useEffect(() => { + const backAction = () => { + if (!menuRef) return false + menuRef.current?.close() + return true + } + const handler = BackHandler.addEventListener('hardwareBackPress', backAction) + return () => handler.remove() + }, []) + const { setCurrentCard } = Characters.useCharacterCard( useShallow((state) => ({ setCurrentCard: state.setCard, @@ -70,11 +109,8 @@ const CharacterNewMenu: React.FC = ({ return ( + entering={SlideInRight.easing(Easing.out(Easing.ease)).duration(300)} + exiting={SlideOutRight.duration(500).easing(Easing.out(Easing.ease))}> = ({ } showPaste /> - { - setShowDownload(true) - }}> - - - - - Characters.importCharacterFromImage().then(async () => { - getCharacterList() - }) - }> - - - { - setShowNewChar(true) - }}> - - + + + + + + { + menuRef.current?.close() + setShowDownload(true) + }} + iconName="cloud-download" + label="Download" + /> + { + menuRef.current?.close() + Characters.importCharacterFromImage().then(async () => { + getCharacterList() + }) + }} + iconName="upload" + label="Import From File" + /> + { + menuRef.current?.close() + setShowNewChar(true) + }} + iconName="pencil" + label="Create Character" + /> + + ) } @@ -128,12 +172,39 @@ const CharacterNewMenu: React.FC = ({ export default CharacterNewMenu const styles = StyleSheet.create({ - headerButtonRight: { - marginLeft: 20, - marginRight: 4, + anchor: { + backgroundColor: Style.getColor('primary-surface3'), + padding: 8, + }, + + popupButton: { + flexDirection: 'row', + alignItems: 'center', + columnGap: 12, + paddingVertical: 12, + paddingRight: 24, + paddingLeft: 12, + borderRadius: 12, }, headerButtonContainer: { flexDirection: 'row', }, + + optionLabel: { + fontSize: 16, + fontWeight: '400', + color: Style.getColor('primary-text1'), + }, }) + +const menustyle: MenuOptionsCustomStyle = { + optionsContainer: { + backgroundColor: Style.getColor('primary-surface3'), + padding: 4, + borderRadius: 12, + }, + optionsWrapper: { + backgroundColor: Style.getColor('primary-surface3'), + }, +}