From 91d46432a4ec72e4701fa773bc0c666b4fe7b0e5 Mon Sep 17 00:00:00 2001 From: balzack Date: Fri, 3 Jan 2025 21:03:15 -0800 Subject: [PATCH] animating carousel --- .../src/conversation/Conversation.styled.ts | 1 + .../mobile/src/conversation/Conversation.tsx | 28 ++++++++++++++++--- .../imageFile/ImageFile.styled.ts | 6 ++++ .../src/conversation/imageFile/ImageFile.tsx | 22 ++++++++------- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/app/client/mobile/src/conversation/Conversation.styled.ts b/app/client/mobile/src/conversation/Conversation.styled.ts index e61192e1..e06ebb07 100644 --- a/app/client/mobile/src/conversation/Conversation.styled.ts +++ b/app/client/mobile/src/conversation/Conversation.styled.ts @@ -14,6 +14,7 @@ export const styles = StyleSheet.create({ carousel: { paddingLeft: 8, paddingBottom: 8, + height: 80, }, assets: { display: 'flex', diff --git a/app/client/mobile/src/conversation/Conversation.tsx b/app/client/mobile/src/conversation/Conversation.tsx index 668673a0..60c73cb7 100644 --- a/app/client/mobile/src/conversation/Conversation.tsx +++ b/app/client/mobile/src/conversation/Conversation.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState, useRef } from 'react'; -import {KeyboardAvoidingView, Modal, Platform, ScrollView, SafeAreaView, Pressable, View, FlatList, TouchableOpacity} from 'react-native'; +import {Animated, useAnimatedValue, KeyboardAvoidingView, Modal, Platform, ScrollView, SafeAreaView, Pressable, View, FlatList, TouchableOpacity} from 'react-native'; import {styles} from './Conversation.styled'; import {useConversation} from './useConversation.hook'; import {Message} from '../message/Message'; @@ -40,6 +40,7 @@ export function Conversation({close}: {close: ()=>void}) { const contentLead = useRef(null); const scrollOffset = useRef(0); const busy = useRef(false); + const scale = useAnimatedValue(0) const alertParams = { title: state.strings.error, @@ -52,6 +53,25 @@ export function Conversation({close}: {close: ()=>void}) { }, }; + useEffect(() => { + +console.log(">>>> ", state.assets.length); + + if (state.assets.length > 0) { + Animated.timing(scale, { + toValue: 80, + duration: 100, + useNativeDriver: false, + }).start(); + } else { + Animated.timing(scale, { + toValue: 0, + duration: 100, + useNativeDriver: false, + }).start(); + } + }, [state.assets]); + const sendMessage = async () => { if (!busy.current && (state.message || state.assets.length > 0)) { busy.current = true; @@ -156,7 +176,7 @@ export function Conversation({close}: {close: ()=>void}) { const media = state.assets.map((asset, index) => { if (asset.type === 'image') { - return {}} /> + return actions.removeAsset(index)} /> } else if (asset.type === 'video') { return {}} /> } else if (asset.type === 'audio') { @@ -238,11 +258,11 @@ export function Conversation({close}: {close: ()=>void}) { - { media.length > 0 && ( + { media } - )} + - + + + + ); }