|
25 | 25 | { index: 18, name: 'SILVER', color: '#bdc3c7' }, |
26 | 26 | { index: 19, name: 'ASBESTOS', color: '#7f8c8d' } |
27 | 27 | ]); |
| 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 | + } |
28 | 51 | </script> |
29 | 52 |
|
30 | 53 | <page> |
|
36 | 59 | the reason is that for this to work in collectionview |
37 | 60 | upon resize animation the Svelte component needs to update its "height" property |
38 | 61 | 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> |
40 | 72 | </Template> |
41 | 73 | </collectionView> |
42 | 74 | </gridLayout> |
|
0 commit comments