Skip to content

Commit 35c231f

Browse files
committed
chore: demo
1 parent 630f022 commit 35c231f

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

demo-snippets/svelte/ResizeCell.svelte

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@
2525
{ index: 18, name: 'SILVER', color: '#bdc3c7' },
2626
{ index: 19, name: 'ASBESTOS', color: '#7f8c8d' }
2727
]);
28+
29+
async function resizeCell(item, event) {
30+
try {
31+
const actualItem = item;
32+
actualItem.showMenu = !actualItem.showMenu;
33+
console.log('resizeCell', actualItem.showMenu)
34+
async function animate(options = {}) {
35+
const newHeight = actualItem.showMenu ? 200 : 100;
36+
return (event.object as View).animate({ height: newHeight, ...options, duration: 300 });
37+
}
38+
39+
const updateItem = () => {
40+
if (item) {
41+
const index = this.items.findIndex((i) => i === item);
42+
// console.log('updateItem', index, item);
43+
this.items.setItem(index, item);
44+
}
45+
};
46+
await animate();
47+
} catch (error) {
48+
console.error(error);
49+
}
50+
}
2851
</script>
2952

3053
<page>
@@ -36,7 +59,16 @@
3659
the reason is that for this to work in collectionview
3760
upon resize animation the Svelte component needs to update its "height" property
3861
otherwise Collectionview bind will report wrong height on cell reuse -->
39-
<ResizeView {item}/>
62+
<gridlayout id="resizeHolder" rows="101,100" on:tap={e=>resizeCell(item,e)} height={item.showMenu === true ? 200 : 100} verticalAlignment="top">
63+
<stacklayout row="0" class="item" backgroundColor={item.color}>
64+
<label row="1" text={item.name} class="title" />
65+
<label row="1" text={item.color} class="subtitle" />
66+
</stacklayout>
67+
<stacklayout row="1" orientation="horizontal" height="100">
68+
<label text="a" width="100" height="100%" backgroundColor="red" textAlignment="center" />
69+
<label text="b" width="100" height="100%" backgroundColor="blue" textAlignment="center" />
70+
</stacklayout>
71+
</gridlayout>
4072
</Template>
4173
</collectionView>
4274
</gridLayout>

demo-snippets/svelte/ResizeView.svelte

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1-
<script lang="ts">
1+
<script context="module" lang="ts">
22
import { View } from '@nativescript/core';
3+
let ID = 0;
4+
</script>
5+
<script lang="ts">
36
export let item;
4-
let height = 100;
5-
$: height = item.showMenu === true ? 200 : 100;
7+
export let height;
8+
const myId = ID++;
9+
10+
function updateheight(item) {
11+
height = item.showMenu === true ? 200 : 100;
12+
console.log('height', myId, height)
13+
}
614
715
async function resizeCell(event) {
816
try {
917
const newValue = item.showMenu === true ? false : true;
10-
item.showMenu = newValue;
18+
console.log('resizeCell', myId, item.showMenu, newValue)
1119
async function animate(options = {}) {
1220
const newHeight = newValue ? 200 : 100;
1321
return (event.object as View).animate({ height: newHeight, ...options, duration: 300 });
1422
}
23+
if (__ANDROID__) {
1524
await animate();
25+
item.showMenu = newValue;
26+
27+
} else {
28+
item.showMenu = newValue;
29+
30+
}
1631
// we update it after so that the svelte component also updates its value
1732
} catch (error) {
1833
console.error(error);

0 commit comments

Comments
 (0)