Skip to content

Commit

Permalink
feat: add waterfall demo
Browse files Browse the repository at this point in the history
  • Loading branch information
keerl committed Nov 7, 2021
1 parent 356f94c commit 12c912d
Show file tree
Hide file tree
Showing 9 changed files with 345 additions and 4 deletions.
9 changes: 7 additions & 2 deletions demo-snippets/ng/install.module.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { NO_ERRORS_SCHEMA, NgModule } from '@angular/core';

import { CollectionViewModule } from "@nativescript-community/ui-collectionview/angular";
import install from '@nativescript-community/ui-collectionview-waterfall';

import { SimpleGridComponent } from './simple-grid/simple-grid.component';
import { SimpleWaterfallComponent } from './simple-waterfall/simple-waterfall.component';

export const COMPONENTS = [SimpleGridComponent];
export const COMPONENTS = [SimpleGridComponent, SimpleWaterfallComponent];
@NgModule({
imports: [CollectionViewModule],
exports: [CollectionViewModule],
schemas: [NO_ERRORS_SCHEMA]
})
export class InstallModule {}

export function installPlugin() {}
export function installPlugin() {
install();
}

export const demos = [
{ name: 'Simple Grid', path: 'simple-grid', component: SimpleGridComponent },
{ name: 'Simple Waterfall', path: 'simple-waterfall', component: SimpleWaterfallComponent },
];
24 changes: 24 additions & 0 deletions demo-snippets/ng/simple-waterfall/simple-waterfall.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<ActionBar>
<NavigationButton android.systemIcon="ic_menu_back" (tap)="goBack()"></NavigationButton>
<Label text="Simple Grid"></Label>
</ActionBar>

<GridLayout>
<CollectionView
iosOverflowSafeArea="true"
[items]="items"
(itemTap)="onItemTap($event)"
(loadMoreItems)="onLoadMoreItems()"
colWidth="50%"
layoutStyle="waterfall"
>
<ng-template let-item="item">
<GridLayout rows="*, auto" [backgroundColor]="item.color" padding="10" [height]="randomHeight(item.color)">
<StackLayout row="1">
<Label row="1" [text]="item.name" color="white" fontSize="17" fontWeight="bold"></Label>
<Label row="1" [text]="item.color" color="white" fontSize="14"></Label>
</StackLayout>
</GridLayout>
</ng-template>
</CollectionView>
</GridLayout>
56 changes: 56 additions & 0 deletions demo-snippets/ng/simple-waterfall/simple-waterfall.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Component, ElementRef, OnInit, ViewChild } from "@angular/core";
import { RouterExtensions } from '@nativescript/angular';

@Component({
selector: 'ns-collectionview-simple-waterfall',
templateUrl: './simple-waterfall.component.html'
})
export class SimpleWaterfallComponent implements OnInit {
constructor(private router: RouterExtensions) {}

items = [
{ index: 0, name: 'TURQUOISE', color: '#1abc9c' },
{ index: 1, name: 'EMERALD', color: '#2ecc71' },
{ index: 2, name: 'PETER RIVER', color: '#3498db' },
{ index: 3, name: 'AMETHYST', color: '#9b59b6' },
{ index: 4, name: 'WET ASPHALT', color: '#34495e' },
{ index: 5, name: 'GREEN SEA', color: '#16a085' },
{ index: 6, name: 'NEPHRITIS', color: '#27ae60' },
{ index: 7, name: 'BELIZE HOLE', color: '#2980b9' },
{ index: 8, name: 'WISTERIA', color: '#8e44ad' },
{ index: 9, name: 'MIDNIGHT BLUE', color: '#2c3e50' },
{ index: 10, name: 'SUN FLOWER', color: '#f1c40f' },
{ index: 11, name: 'CARROT', color: '#e67e22' },
{ index: 12, name: 'ALIZARIN', color: '#e74c3c' },
{ index: 13, name: 'CLOUDS', color: '#ecf0f1' },
{ index: 14, name: 'CONCRETE', color: '#95a5a6' },
{ index: 15, name: 'ORANGE', color: '#f39c12' },
{ index: 16, name: 'PUMPKIN', color: '#d35400' },
{ index: 17, name: 'POMEGRANATE', color: '#c0392b' },
{ index: 18, name: 'SILVER', color: '#bdc3c7' },
{ index: 19, name: 'ASBESTOS', color: '#7f8c8d' }
];

ngOnInit(): void {

}

goBack(): void {
this.router.back();
}

onItemTap({ index, item }) {
console.log(`EVENT TRIGGERED: Tapped on ${index} ${item.name}`);
}

onLoadMoreItems() {
console.log('EVENT TRIGGERED: onLoadMoreItems()');
}

randomHeight(color) {
if (parseInt(color.substr(1), 16) % 2 === 0) {
return 200;
}
return 150;
}
}
69 changes: 69 additions & 0 deletions demo-snippets/react/SimpleWaterfall.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as React from 'react';
import { CollectionView } from '@nativescript-community/ui-collectionview/react';
import { StyleSheet } from 'react-nativescript';
import { FontWeight } from '@nativescript/core/ui/styling/font';

const items = [
{ index: 0, name: 'TURQUOISE', color: '#1abc9c' },
{ index: 1, name: 'EMERALD', color: '#2ecc71' },
{ index: 2, name: 'PETER RIVER', color: '#3498db' },
{ index: 3, name: 'AMETHYST', color: '#9b59b6' },
{ index: 4, name: 'WET ASPHALT', color: '#34495e' },
{ index: 5, name: 'GREEN SEA', color: '#16a085' },
{ index: 6, name: 'NEPHRITIS', color: '#27ae60' },
{ index: 7, name: 'BELIZE HOLE', color: '#2980b9' },
{ index: 8, name: 'WISTERIA', color: '#8e44ad' },
{ index: 9, name: 'MIDNIGHT BLUE', color: '#2c3e50' },
{ index: 10, name: 'SUN FLOWER', color: '#f1c40f' },
{ index: 11, name: 'CARROT', color: '#e67e22' },
{ index: 12, name: 'ALIZARIN', color: '#e74c3c' },
{ index: 13, name: 'CLOUDS', color: '#ecf0f1' },
{ index: 14, name: 'CONCRETE', color: '#95a5a6' },
{ index: 15, name: 'ORANGE', color: '#f39c12' },
{ index: 16, name: 'PUMPKIN', color: '#d35400' },
{ index: 17, name: 'POMEGRANATE', color: '#c0392b' },
{ index: 18, name: 'SILVER', color: '#bdc3c7' },
{ index: 19, name: 'ASBESTOS', color: '#7f8c8d' },
];

interface Item {
index: number;
name: string;
color: string;
}

const randomHeight = (color) => {
if (parseInt(color.substr(1), 16) % 2 === 0) {
return 200;
}
return 150;
}

const cellFactory = (item: Item) => (
<gridLayout rows="*, auto" backgroundColor={item.color} style={styles.item} height={randomHeight(item.color)}>
<stackLayout row={1}>
<label text={item.name} style={styles.title} />
<label text={item.color} style={styles.subtitle} />
</stackLayout>
</gridLayout>
);

export function SimpleWaterfall() {
return (
<CollectionView iosOverflowSafeArea={true} items={items} colWidth="50%" cellFactory={cellFactory} layoutStyle="waterfall" width="100%" height="100%" />
);
}

const styles = StyleSheet.create({
item: {
padding: 10,
color: 'white'
},
title: {
fontSize: 17,
fontWeight: FontWeight.BOLD
},
subtitle: {
fontSize: 14
}
});
7 changes: 6 additions & 1 deletion demo-snippets/react/install.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { SimpleGrid } from './SimpleGrid';
import { registerCollectionView } from '@nativescript-community/ui-collectionview/react';
import install from '@nativescript-community/ui-collectionview-waterfall';

import { SimpleGrid } from './SimpleGrid';
import { SimpleWaterfall } from './SimpleWaterfall';

export function installPlugin() {
registerCollectionView();
install();
}

export const demos = [
{ name: 'Simple Grid', path: 'simple-grid', component: SimpleGrid },
{ name: 'Simple Waterfall', path: 'simple-waterfall', component: SimpleWaterfall }
];
79 changes: 79 additions & 0 deletions demo-snippets/svelte/SimpleWaterfall.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<script lang="typescript">
import { Template } from 'svelte-native/components';
const items = [
{ index: 0, name: 'TURQUOISE', color: '#1abc9c' },
{ index: 1, name: 'EMERALD', color: '#2ecc71' },
{ index: 2, name: 'PETER RIVER', color: '#3498db' },
{ index: 3, name: 'AMETHYST', color: '#9b59b6' },
{ index: 4, name: 'WET ASPHALT', color: '#34495e' },
{ index: 5, name: 'GREEN SEA', color: '#16a085' },
{ index: 6, name: 'NEPHRITIS', color: '#27ae60' },
{ index: 7, name: 'BELIZE HOLE', color: '#2980b9' },
{ index: 8, name: 'WISTERIA', color: '#8e44ad' },
{ index: 9, name: 'MIDNIGHT BLUE', color: '#2c3e50' },
{ index: 10, name: 'SUN FLOWER', color: '#f1c40f' },
{ index: 11, name: 'CARROT', color: '#e67e22' },
{ index: 12, name: 'ALIZARIN', color: '#e74c3c' },
{ index: 13, name: 'CLOUDS', color: '#ecf0f1' },
{ index: 14, name: 'CONCRETE', color: '#95a5a6' },
{ index: 15, name: 'ORANGE', color: '#f39c12' },
{ index: 16, name: 'PUMPKIN', color: '#d35400' },
{ index: 17, name: 'POMEGRANATE', color: '#c0392b' },
{ index: 18, name: 'SILVER', color: '#bdc3c7' },
{ index: 19, name: 'ASBESTOS', color: '#7f8c8d' }
];
function onItemTap({ index, item }) {
console.log(`EVENT TRIGGERED: Tapped on ${index} ${item.name}`);
}
function onLoadMoreItems() {
console.log('EVENT TRIGGERED: onLoadMoreItems()');
}
function randomHeight(color) {
if (parseInt(color.substr(1), 16) % 2 === 0) {
return 200;
}
return 150;
}
</script>

<page>
<actionBar title="Simple Grid" />
<gridLayout>
<collectionView
{items}
iosOverflowSafeArea="true"
colWidth="50%"
on:itemTap="{onItemTap}"
on:loadMoreItems="{onLoadMoreItems}"
layoutStyle="waterfall"
>
<Template let:item>
<gridlayout height="{randomHeight(item.color)}" rows="*, auto" backgroundColor="{item.color}" class="item">
<stacklayout row="1">
<label row="1" text="{item.name}" class="title" />
<label row="1" text="{item.color}" class="subtitle" />
</stacklayout>
</gridlayout>
</Template>
</collectionView>
</gridLayout>
</page>

<style>
ActionBar {
background-color:#ed3e04;
color: white;
}
.item {
padding: 10;
color: white;
}
.title {
font-size: 17;
font-weight: bold;
}
.subtitle {
font-size: 14;
}
</style>
5 changes: 4 additions & 1 deletion demo-snippets/svelte/install.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import CollectionViewElement from '@nativescript-community/ui-collectionview/svelte';
CollectionViewElement.register();
import install from '@nativescript-community/ui-collectionview-waterfall';

import SimpleGrid from './SimpleGrid.svelte';
import SimpleWaterfall from './SimpleWaterfall.svelte';

export function installPlugin() {
CollectionViewElement.register();
install();
}

export const demos = [
{ name: 'Simple Grid', path: 'simple-grid', component: SimpleGrid },
{ name: 'Simple Waterfall', path: 'simple-waterfall', component: SimpleWaterfall }
];
96 changes: 96 additions & 0 deletions demo-snippets/vue/SimpleWaterfall.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<template>
<Page>
<ActionBar>
<Label text="Simple Waterfall" />
</ActionBar>

<GridLayout>
<CollectionView
iosOverflowSafeArea="true"
:items="itemList"
@itemTap="onItemTap"
@loadMoreItems="onLoadMoreItems"
@itemLoadingEvent="onItemLoadingEvent"
itemIdGenerator="index"
colWidth="50%"
layoutStyle="waterfall"
>
<v-template>
<GridLayout :height="randomHeight(item.color)" id="test" rows="*, auto" :backgroundColor="item.color" class="item">
<StackLayout row="1">
<Label row="1" :text="item.name" class="title" />
<Label row="1" :text="item.color" class="subtitle" />
</StackLayout>
</GridLayout>
</v-template>
</CollectionView>
</GridLayout>
</Page>
</template>

<script>
import { ObservableArray } from '@nativescript/core';
export default {
data() {
const items = new ObservableArray([
{ index: 0, name: 'TURQUOISE', color: '#1abc9c' },
{ index: 1, name: 'EMERALD', color: '#2ecc71' },
{ index: 2, name: 'PETER RIVER', color: '#3498db' },
{ index: 3, name: 'AMETHYST', color: '#9b59b6' },
{ index: 4, name: 'WET ASPHALT', color: '#34495e' },
{ index: 5, name: 'GREEN SEA', color: '#16a085' },
{ index: 6, name: 'NEPHRITIS', color: '#27ae60' },
{ index: 7, name: 'BELIZE HOLE', color: '#2980b9' },
{ index: 8, name: 'WISTERIA', color: '#8e44ad' },
{ index: 9, name: 'MIDNIGHT BLUE', color: '#2c3e50' },
{ index: 10, name: 'SUN FLOWER', color: '#f1c40f' },
{ index: 11, name: 'CARROT', color: '#e67e22' },
{ index: 12, name: 'ALIZARIN', color: '#e74c3c' },
{ index: 13, name: 'CLOUDS', color: '#ecf0f1' },
{ index: 14, name: 'CONCRETE', color: '#95a5a6' },
{ index: 15, name: 'ORANGE', color: '#f39c12' },
{ index: 16, name: 'PUMPKIN', color: '#d35400' },
{ index: 17, name: 'POMEGRANATE', color: '#c0392b' },
{ index: 18, name: 'SILVER', color: '#bdc3c7' },
{ index: 19, name: 'ASBESTOS', color: '#7f8c8d' }
]);
return {
itemList: items
};
},
methods: {
onItemTap({ index, item }) {
console.log(`EVENT TRIGGERED: Tapped on ${index} ${item.name}`);
},
onLoadMoreItems() {
console.log('EVENT TRIGGERED: onLoadMoreItems()');
},
logEvent(e) {
console.log('logEvent', e.eventName, e.extraData);
},
randomHeight(color) {
if (parseInt(color.substr(1), 16) % 2 === 0) {
return 200;
}
return 150;
}
}
};
</script>

<style scoped lang="scss">
ActionBar {
background-color: #42b883;
}
.item {
padding: 10;
color: white;
.title {
font-size: 17;
font-weight: bold;
}
.subtitle {
font-size: 14;
}
}
</style>
Loading

0 comments on commit 12c912d

Please sign in to comment.