Skip to content

Commit

Permalink
使用瀑布流视图
Browse files Browse the repository at this point in the history
  • Loading branch information
Gandum2077 committed Mar 11, 2020
1 parent cd2710f commit 4d5781c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"info": {
"name": "JSBooru",
"url": "",
"version": "2.0.2",
"version": "2.0.3",
"author": "Gandum2077",
"website": "https://github.com/Gandum2077/JSBooru",
"types": 1
Expand Down
24 changes: 22 additions & 2 deletions scripts/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,30 @@ class Controller {
}
});
this.views.booruView = new ContentView({
bgcolor: $color("#333"),
layout: (make, view) => {
make.left.right.top.inset(0);
make.bottom.equalTo(this.views.footerBar.view.top);
}
});
this.views.favoritesView = new ContentView({
bgcolor: $color("#333"),
layout: (make, view) => {
make.left.right.top.inset(0);
make.bottom.equalTo(this.views.footerBar.view.top);
}
});
this.views.thumbnailsViewBooru = new ThumbnailsView({
layout: (make, view) => {
make.left.right.bottom.inset(0)
make.top.inset(36)
},
events: {
itemSize: function(sender, indexPath) {
const index = indexPath.item
const info = classThis.booruItems[index]
return $size(info.width, info.height)
},
pulled: async function(sender) {
if (classThis.isLoading) {
sender.endRefreshing();
Expand Down Expand Up @@ -115,7 +126,16 @@ class Controller {
}
});
this.views.thumbnailsViewFavorites = new ThumbnailsView({
layout: (make, view) => {
make.left.right.bottom.inset(0)
make.top.inset(36)
},
events: {
itemSize: function(sender, indexPath) {
const index = indexPath.item
const info = classThis.favoritesItems[index]
return $size(info.width, info.height)
},
pulled: async function(sender) {
classThis.loadFavorites({
startPage: classThis.favoritesInfo.startPage
Expand All @@ -140,8 +160,8 @@ class Controller {
didReachBottom: async function(sender) {
const result = classThis.generatorFavorites.next();
if (!result.done) {
ITEMS.push(...result.value);
sender.data = getDataForListView(ITEMS);
classThis.favoritesItems.push(...result.value);
classThis.views.thumbnailsViewFavorites.items = classThis.favoritesItems;
}
sender.endFetchingMore();
}
Expand Down
13 changes: 11 additions & 2 deletions scripts/views/tagsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ class Menu extends BaseView {
}

class ListView extends BaseView {
constructor() {
constructor({searchEvent}) {
super();
this.searchEvent = searchEvent
}

_defineView() {
const classThis = this
return {
type: "list",
props: {
Expand Down Expand Up @@ -110,6 +112,12 @@ class ListView extends BaseView {
layout: (make, view) => {
make.left.right.bottom.inset(0);
make.top.equalTo(view.prev.bottom);
},
events: {
didSelect: (sender, indexPath, data) => {
const name = classThis._rawData[indexPath.item].name
classThis.searchEvent(name)
}
}
};
}
Expand All @@ -119,6 +127,7 @@ class ListView extends BaseView {
if (!text) return 0;
return text.length;
};
this._rawData = items
this.view.data = items.map(n => {
return {
label: {
Expand Down Expand Up @@ -172,7 +181,7 @@ class TagsView extends BaseView {
items: [...FIXED_ITEMS, ...constants.userConfig.tag_categoires],
changedEvent: text => classThis.reload()
});
this.listView = new ListView();
this.listView = new ListView({searchEvent: this.searchEvent});
return {
type: "view",
props: {
Expand Down
9 changes: 1 addition & 8 deletions scripts/views/thumbnailsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,10 @@ class ThumbnailsView extends BaseView {
type: "matrix",
props: {
id: this.id,
square: true,
waterfall: true,
columns: this.columns,
spacing: 5,
bgcolor: $color("#333"),
header: {
type: "view",
props: {
height: 36,
bgcolor: $color("clear")
}
},
template: {
props: {
bgcolor: $color("clear")
Expand Down

0 comments on commit 4d5781c

Please sign in to comment.