1+ <script lang="ts" setup>
2+ import { ref , $navigateTo , $showModal } from ' nativescript-vue' ;
3+ import { HEIGH_CARD , dataCards } from ' ./carddata' ;
4+ import { isAndroid , ObservableArray , PageTransition , SharedTransition , View , ModalTransition , Screen } from ' @nativescript/core' ;
5+ import { animateView , configHomeSharedTransition } from ' ./animation' ;
6+ import Card from ' ./Card.vue' ;
7+ // import Details from "./Details.vue";
8+
9+ const isOpen = ref (false );
10+ const refShowBtn = ref ();
11+ const refAddBtn = ref ();
12+ const refTextHeader = ref ();
13+
14+ const items = new ObservableArray (dataCards );
15+
16+ const transaleY = 70 ;
17+ const viewCards: View [] = [];
18+
19+ function loadedCard(args : any , index : number ) {
20+ const card: View = args .object ;
21+ if (! isOpen .value && viewCards .length < dataCards .length ) {
22+ viewCards .push (card );
23+ card .translateY = - (HEIGH_CARD - transaleY ) * index ;
24+ }
25+ }
26+
27+ function toggleStatus() {
28+ const showBtn: View = refShowBtn .value .nativeView ;
29+ const addBtn: View = refAddBtn .value .nativeView ;
30+ const addWalletBtn: View = addBtn .getViewById (' icon-add' );
31+ const textHeader: View = refTextHeader .value .nativeView ;
32+
33+ if (isOpen .value ) {
34+ viewCards .forEach ((cardView , index ) => index == 0 || close (cardView , index ));
35+ animateView (addBtn , { translate: { y: 0 , x: 0 }, alpha: 1 , rotation: 0 });
36+ animateView (addWalletBtn , { rotation: 0 });
37+ animateView (showBtn , { rotation: 90 , alpha: 0 });
38+ animateView (textHeader , { translate: { x: 0 , y: 0 } });
39+ } else {
40+ viewCards .forEach ((cardView ) => open (cardView ));
41+ animateView (addBtn , { translate: { y: 50 , x: 0 }, alpha: 0 });
42+ animateView (addWalletBtn , { rotation: 180 });
43+ animateView (showBtn , { rotation: 0 , alpha: 1 });
44+ animateView (textHeader , { translate: { x: - (Screen .mainScreen .widthDIPs / 2 ) + textHeader .getActualSize ().width / 2 + 10 , y: 0 } });
45+ }
46+ isOpen .value = ! isOpen .value ;
47+ }
48+
49+ function open(cardView : View ) {
50+ animateView (cardView , { translate: { x: 0 , y: 0 } });
51+ }
52+
53+ function close(cardView : View , index : number ) {
54+ animateView (cardView , { translate: { x: 0 , y: - (HEIGH_CARD - transaleY ) * index } });
55+ }
56+
57+ function openOrGoToDetails(index : number ) {
58+ // if (isOpen.value) {
59+ // if (isAndroid) {
60+ // $navigateTo(Details, {
61+ // transition: SharedTransition.custom(new PageTransition(), configHomeSharedTransition),
62+ // props: { index, card: dataCards[index] }
63+ // });
64+ // } else {
65+ // $showModal(Details, {
66+ // transition: SharedTransition.custom(new ModalTransition(), configHomeSharedTransition),
67+ // props: { index, card: dataCards[index] }
68+ // });
69+ // }
70+ // } else {
71+ toggleStatus ();
72+ // }
73+ }
74+ let currentToggledIndex = - 1 ;
75+ function toggleItemHeight(item ) {
76+ const index = items .findIndex ((i ) => i .id === item .id );
77+ if (index >= 0 ) {
78+ if (! item .expanded && currentToggledIndex !== - 1 ) {
79+ const currentItem = items .getItem (currentToggledIndex );
80+ currentItem .expanded = false ;
81+ items .setItem (currentToggledIndex , currentItem );
82+ }
83+ item .expanded = !!! item .expanded ;
84+ currentToggledIndex = item .expanded ? index : - 1 ;
85+ items .setItem (index , item );
86+ }
87+ }
88+ </script >
89+
90+ <template >
91+ <Page actionBarHidden =" true" androidStatusBarBackground =" transparent" class =" bg-white" >
92+ <GridLayout rows =" auto,*,auto" >
93+ <GridLayout height =" 50" android:marginop =" 3" >
94+ <Label ref =" refTextHeader" text =" Wallet" class =" text-3xl font-bold text-black" horizontalAlignment =" center" ></Label >
95+ <Label ref =" refShowBtn" text =" close" style =" font-size : 24 ;" height =" 45" width =" 45" rotate =" 90" class =" m-icon-round bg-[#0666eb] rounded-full text-white text-center opacity-0 mr-2" horizontalAlignment =" right" @tap =" toggleStatus" ></Label >
96+ </GridLayout >
97+ <CollectionView row =" 1" height =" 100%" :items =" items" itemIdGenerator =" index" :itemOverlap =" `-${HEIGH_CARD - 60} 0 0 0`" >
98+ <template #default =" { item } " >
99+ <GridLayout :height =" item.expanded ? 2*HEIGH_CARD - 60 : HEIGH_CARD" >
100+ <Card :height =" HEIGH_CARD" :data =" item" :sharedTransitionTag =" `card_${item.id}`" @tap =" toggleItemHeight(item)" verticalAlignment =" top" >
101+ </Card >
102+ </GridLayout >
103+ </template >
104+ </CollectionView >
105+ <!-- <FlexboxLayout height="100%" marginTop="2" flexDirection="column">
106+ <Card v-for="(card, index) in dataCards" :key="index" :style="{ 'height': HEIGH_CARD }" :data="card" :sharedTransitionTag="`card_${index}`" @loaded="loadedCard($event, index)" @tap="openOrGoToDetails(index)">
107+ </Card>
108+ </FlexboxLayout> -->
109+ <FlexboxLayout ref =" refAddBtn" verticalAlignment =" bottom" class =" justify-center items-center" height =" 100" >
110+ <Label id =" icon-add" text =" add" height =" 60" width =" 60" class =" m-icon-round bg-[#0666eb] text-center text-white rounded-xl" ></Label >
111+ </FlexboxLayout >
112+ </GridLayout >
113+ </Page >
114+ </template >
0 commit comments