Skip to content

Commit 40c033b

Browse files
committed
Added new component SwipeListItemView
1 parent 872c2f1 commit 40c033b

File tree

14 files changed

+581
-40
lines changed

14 files changed

+581
-40
lines changed

examples/lib/MenuPage.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import PageView from '../../lib/PageView';
55
import OsBarView from '../../lib/navigations/OsBarView';
66
import ListView from '../../lib/listviews/ListView';
77
import DifferentSizeListViewPage from './DifferentSizeListViewPage';
8+
import SwipeListViewPage from './SwipeListViewPage';
89

910
export default class MenuPage extends PageView {
1011

@@ -18,6 +19,7 @@ export default class MenuPage extends PageView {
1819
this.template = require('../templates/menu.html');
1920

2021
this.addEvents({
22+
'click .js-swipe-list-item': 'onSwipeListItemClick',
2123
'click .js-different-size': 'onDifferentSizeClick',
2224
'click .js-different-size-with-header': 'onDifferentSizeWithHeaderClick',
2325
'click .js-different-size-with-2-columns': 'onDifferentSizeWith2ColumnsClick',
@@ -26,7 +28,7 @@ export default class MenuPage extends PageView {
2628
'click .js-horizontal-different-size': 'onHorizontalDifferentSizeClick',
2729
'click .js-horizontal-different-size-with-header': 'onHorizontalDifferentSizeWithHeaderClick',
2830
'click .js-horizontal-different-size-with-2-columns': 'onHorizontalDifferentSizeWith2ColumnsClick',
29-
'click .js-horizontal-different-size-with-3-columns': 'onHorizontalDifferentSizeWith3ColumnsClick'
31+
'click .js-horizontal-different-size-with-3-columns': 'onHorizontalDifferentSizeWith3ColumnsClick',
3032
});
3133

3234
let state = this.getState();
@@ -51,7 +53,11 @@ export default class MenuPage extends PageView {
5153

5254
//
5355
// Vertial list view
54-
//
56+
57+
onSwipeListItemClick() {
58+
const swipeListViewPage = new SwipeListViewPage();
59+
context.viewstack.pushView(swipeListViewPage);
60+
}
5561

5662
onDifferentSizeClick() {
5763
const differentSizeListViewPage = new DifferentSizeListViewPage();

examples/lib/SwipeListView.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import _ from 'underscore';
2+
import $ from 'jquery';
3+
import ListView from '../../lib/listviews/ListView';
4+
import SwipeListItemView from '../../lib/listviews/SwipeListItemView';
5+
6+
class MySwipeListItemView extends SwipeListItemView {
7+
8+
constructor(options) {
9+
super(options);
10+
}
11+
12+
onRender(rendered) {
13+
super.onRender(rendered);
14+
this.cache.$drawer.html('<p>Title</p><p>Description description description</p><p>Short description</p>');
15+
}
16+
17+
}
18+
19+
export default class SwipeListView extends ListView {
20+
21+
getListItemViewAtIndexWithOptions(index, options) {
22+
return new MySwipeListItemView(options);
23+
}
24+
25+
onSelectItem(item, done) {
26+
if (item) {
27+
console.log(item.element);
28+
}
29+
return done();
30+
}
31+
32+
}

examples/lib/SwipeListViewPage.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import _ from 'underscore';
2+
import $ from 'jquery';
3+
import context from 'context-utils';
4+
import { Collection } from 'backbone';
5+
import PageView from '../../lib/PageView';
6+
import OsBarView from '../../lib/navigations/OsBarView';
7+
import SwipeListView from './SwipeListView';
8+
import ModelA from './models/ModelA';
9+
10+
export default class SwipeListViewPage extends PageView {
11+
12+
addClass() {
13+
return 'swipe-list-view';
14+
}
15+
16+
constructor(options) {
17+
super(options);
18+
19+
const state = this.getState();
20+
const navigationBarView = new OsBarView({
21+
state: state,
22+
addClass: 'back-bar',
23+
left: '<span>Back</span>',
24+
center: $('<span class="title"></span>').text('Swipe list view'),
25+
popViewOnBackButton: true
26+
});
27+
this.addSubView('navigationBarView', navigationBarView);
28+
29+
this.initCollection();
30+
31+
const listView = new SwipeListView(_.extend(this.options.listview || {}, {
32+
collection: this.collection,
33+
itemClass: 'ui-swipe-list-item'
34+
}));
35+
this.addSubView('listView', listView);
36+
37+
this.listenTo(listView, 'swipe:left', (view) => { console.log(view) });
38+
this.listenTo(listView, 'swipe:right', (view) => { console.log(view) });
39+
40+
// For debug
41+
window.__listView = listView;
42+
}
43+
44+
getNavigationBar() {
45+
return this.getSubView('navigationBarView');
46+
}
47+
48+
onRender(rendered) {
49+
if (!rendered) {
50+
const listView = this.getSubView('listView');
51+
this.$el.append(listView.el);
52+
listView.render();
53+
}
54+
}
55+
56+
//
57+
// Utils
58+
//
59+
60+
initCollection() {
61+
const models = [];
62+
let aModelClass;
63+
for (var i = 0; i < 30; i++) {
64+
models.push(new ModelA({
65+
id: i
66+
}));
67+
}
68+
69+
const collection = new Collection(models);
70+
this.collection = collection;
71+
}
72+
73+
}

examples/lib/app.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import NavigationView from '../../lib/navigations/NavigationView';
44
import MenuPage from './MenuPage';
55
import requestNextAnimationFrame from '../../lib/utils/requestAnimationFrame';
66

7+
context.uikit = {
8+
SwipeListItemView: {
9+
vibrate: () => {
10+
if (window.TapticEngine) {
11+
window.TapticEngine.selection();
12+
}
13+
}
14+
}
15+
};
16+
717
const viewstack = context.viewstack = new Viewstack({ el: '#application' });
818
viewstack.render();
919

examples/lib/models/ModelA.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import { Model } from 'backbone';
22

3-
export default class ModelA extends Model {};
3+
export default class ModelA extends Model {
4+
5+
toString() {
6+
return this.id;
7+
}
8+
9+
};

examples/lib/models/ModelB.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import { Model } from 'backbone';
22

3-
export default class ModelB extends Model {};
3+
export default class ModelB extends Model {
4+
5+
toString() {
6+
return this.id;
7+
}
8+
9+
};

examples/lib/models/ModelC.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import { Model } from 'backbone';
22

3-
export default class ModelC extends Model {};
3+
export default class ModelC extends Model {
4+
5+
toString() {
6+
return this.id;
7+
}
8+
9+
};

examples/styles/style.scss

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11

2-
$toolbar-height: 44px;
32
$overlay-color: rgba(40,47,57,0.27);
43

54
$regular-font: 'helvetica';
65
$bold-font: 'helvetica';
76
$italic-font: 'helvetica';
87

98
$nav-height: 44px;
9+
$tab-height: 50px;
10+
$toolbar-height: 44px;
11+
$ios-iphone-x-margin-bottom: 20px;
1012

1113
$icon-font: 'unieuro';
1214

@@ -16,6 +18,11 @@ $icon-font: 'unieuro';
1618
// Example style
1719
//
1820

21+
html, body {
22+
height: 100%;
23+
overflow: hidden;
24+
}
25+
1926
#application {
2027
position: absolute;
2128
top: 0;
@@ -77,3 +84,41 @@ $icon-font: 'unieuro';
7784
.menu-page {
7885
padding: 0 20px;
7986
}
87+
88+
89+
// Swipe list item view
90+
.ui-swipe-list-item {
91+
height: 120px;
92+
}
93+
.ui-swipe-list-item-drawer {
94+
position: absolute;
95+
top: 0;
96+
right: 0;
97+
bottom: 0;
98+
left: 0;
99+
z-index: 1;
100+
background-color: white;
101+
box-sizing: border-box;
102+
border-bottom: 1px solid #eee;
103+
}
104+
.ui-swipe-list-item-actions {
105+
position: absolute;
106+
top: 0;
107+
right: 0;
108+
bottom: 0;
109+
left: 0;
110+
z-index: 0;
111+
background-color: #ccc;
112+
}
113+
.ui-swipe-list-item-actions-left {
114+
right: 50%;
115+
}
116+
.action-active .ui-swipe-list-item-actions-left {
117+
background-color: #f2ab33;
118+
}
119+
.ui-swipe-list-item-actions-right {
120+
left: 50%;
121+
}
122+
.action-active .ui-swipe-list-item-actions-right {
123+
background-color: #df1c1c;
124+
}

examples/templates/menu.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<h1>ListView</h1>
22
<h2>Vertical</h2>
33
<div>
4+
<button class="button js-swipe-list-item">Swipe list item</button>
45
<button class="button js-different-size">Different size</button>
56
<button class="button js-different-size-with-header">With header</button>
67
<button class="button js-different-size-with-2-columns">With 2 columns</button>

lib/listviews/ListItemView.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export default class ListItemView extends BaseView {
77
constructor(options) {
88
super(options);
99

10+
if (options && options.parentList) {
11+
this.parent = options.parentList;
12+
}
13+
1014
this._visibility = false;
1115

1216
this.listenTo(this.model, 'change', this.render);

0 commit comments

Comments
 (0)