Skip to content

Commit d1c92b1

Browse files
committed
chore: demo for resize
1 parent b0343f8 commit d1c92b1

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<script lang="ts">
2+
import { ObservableArray, View } from '@nativescript/core';
3+
import { Template } from 'svelte-native/components';
4+
import ResizeView from './ResizeView.svelte';
5+
6+
let items = new ObservableArray([
7+
{ index: 0, name: 'TURQUOISE', color: '#1abc9c' },
8+
{ index: 1, name: 'EMERALD', color: '#2ecc71' },
9+
{ index: 2, name: 'PETER RIVER', color: '#3498db' },
10+
{ index: 3, name: 'AMETHYST', color: '#9b59b6' },
11+
{ index: 4, name: 'WET ASPHALT', color: '#34495e' },
12+
{ index: 5, name: 'GREEN SEA', color: '#16a085' },
13+
{ index: 6, name: 'NEPHRITIS', color: '#27ae60' },
14+
{ index: 7, name: 'BELIZE HOLE', color: '#2980b9' },
15+
{ index: 8, name: 'WISTERIA', color: '#8e44ad' },
16+
{ index: 9, name: 'MIDNIGHT BLUE', color: '#2c3e50' },
17+
{ index: 10, name: 'SUN FLOWER', color: '#f1c40f' },
18+
{ index: 11, name: 'CARROT', color: '#e67e22' },
19+
{ index: 12, name: 'ALIZARIN', color: '#e74c3c' },
20+
{ index: 13, name: 'CLOUDS', color: '#ecf0f1' },
21+
{ index: 14, name: 'CONCRETE', color: '#95a5a6' },
22+
{ index: 15, name: 'ORANGE', color: '#f39c12' },
23+
{ index: 16, name: 'PUMPKIN', color: '#d35400' },
24+
{ index: 17, name: 'POMEGRANATE', color: '#c0392b' },
25+
{ index: 18, name: 'SILVER', color: '#bdc3c7' },
26+
{ index: 19, name: 'ASBESTOS', color: '#7f8c8d' }
27+
]);
28+
</script>
29+
30+
<page>
31+
<actionBar title="Resize Cell" />
32+
<gridLayout rows="auto,*">
33+
<collectionView {items} row="1" autoReloadItemOnLayout={true}>
34+
<Template let:item>
35+
<!-- it is important to use a custom component
36+
the reason is that for this to work in collectionview
37+
upon resize animation the Svelte component needs to update its "height" property
38+
otherwise Collectionview bind will report wrong height on cell reuse -->
39+
<ResizeView {item}/>
40+
</Template>
41+
</collectionView>
42+
</gridLayout>
43+
</page>
44+
45+
<style>
46+
ActionBar {
47+
background-color: #ed3e04;
48+
color: white;
49+
}
50+
.item {
51+
padding: 10;
52+
color: white;
53+
}
54+
.title {
55+
font-size: 17;
56+
font-weight: bold;
57+
}
58+
.subtitle {
59+
font-size: 14;
60+
}
61+
</style>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script lang="ts">
2+
import { View } from '@nativescript/core';
3+
export let item;
4+
5+
$: height = item.showMenu === true ? 200 : 100;
6+
7+
async function resizeCell(event) {
8+
try {
9+
async function animate(options = {}) {
10+
const newHeight = !item.showMenu ? 200 : 100;
11+
return (event.object as View).animate({ height: newHeight, ...options, duration: 300 });
12+
}
13+
await animate();
14+
// we update it after so that the svelte component also updates its value
15+
item.showMenu = !item.showMenu;
16+
} catch (error) {
17+
console.error(error);
18+
}
19+
}
20+
</script>
21+
22+
<gridlayout rows="101,100" on:tap={resizeCell} height={height}>
23+
<stacklayout row="0" class="item" backgroundColor={item.color}>
24+
<label row="1" text={item.name} class="title" />
25+
<label row="1" text={item.color} class="subtitle" />
26+
</stacklayout>
27+
<stacklayout row="1" orientation="horizontal" height="100">
28+
<label text="a" width="100" height="100%" backgroundColor="red" textAlignment="center" />
29+
<label text="b" width="100" height="100%" backgroundColor="blue" textAlignment="center" />
30+
</stacklayout>
31+
</gridlayout>

demo-snippets/svelte/install.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import CollectionViewElement from '@nativescript-community/ui-collectionview/svelte';
2+
import {CollectionViewTraceCategory} from '@nativescript-community/ui-collectionview';
23
import install from '@nativescript-community/ui-collectionview-waterfall';
34
import SwipeMenuElement from '@nativescript-community/ui-collectionview-swipemenu/svelte';
5+
import {Trace} from '@nativescript/core';
46

57
import SimpleGrid from './SimpleGrid.svelte';
68
import HorizontalGrid from './HorizontalGrid.svelte';
79
import SimpleWaterfall from './SimpleWaterfall.svelte';
810
import SimpleTemplates from './SimpleTemplates.svelte';
911
import SwipeMenu from './SwipeMenu.svelte';
12+
import ResizeCell from './ResizeCell.svelte';
1013

1114
export function installPlugin() {
1215
CollectionViewElement.register();
@@ -19,5 +22,9 @@ export const demos = [
1922
{ name: 'Horizontal Grid', path: 'horizontal-grid', component: HorizontalGrid },
2023
{ name: 'Simple Waterfall', path: 'simple-waterfall', component: SimpleWaterfall },
2124
{ name: 'Simple Templates', path: 'simple-templates', component: SimpleTemplates },
22-
{ name: 'SwipeMenu', path: 'swipe-menu', component: SwipeMenu }
25+
{ name: 'SwipeMenu', path: 'swipe-menu', component: SwipeMenu },
26+
{ name: 'ResizeCell', path: 'resize-cell', component: ResizeCell }
2327
];
28+
29+
// Trace.addCategories(CollectionViewTraceCategory)
30+
// Trace.enable()

demo-snippets/vue/ResizeCell.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
</GridLayout> -->
1919
<CollectionView :items="items" ref="collectionView" row="1" :autoReloadItemOnLayout="true">
2020
<v-template>
21+
22+
<!-- TODO: it needs to be a custom Vue component for the component height to update it s value for height upon finished animation -->
2123
<GridLayout class="item" rows="101,100" @tap="resizeCell(item, $event)" :height="getItemHeight(item)" :backgroundColor="item.color">
2224
<Stacklayout row="0">
2325
<Label row="1" :text="item.name" class="title" />

0 commit comments

Comments
 (0)