Skip to content

Commit

Permalink
Merge pull request #34 from w771854332/feat/better_systeminfo_get
Browse files Browse the repository at this point in the history
在组件生命周期内调用getSystemInfo,优化首屏性能
  • Loading branch information
linxz authored Jul 6, 2020
2 parents 1d7de83 + 4c87bf1 commit 2771e39
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6,640 deletions.
13 changes: 11 additions & 2 deletions src/swipe-action/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import fmtUnit from '../_util/fmtUnit';

const { windowWidth } = my.getSystemInfoSync();
const isV2 = my.canIUse('movable-view.onTouchStart');

Component({
data: {
leftPos: 0,
swiping: false,
holdSwipe: true,
viewWidth: windowWidth,
viewWidth: 0,
x: 0,
actionWidth: 0,
transitionVal: 'none',
Expand Down Expand Up @@ -38,6 +37,7 @@ Component({
}
this.setBtnWidth();
this.getSwipeHeight();
this.setWindowWidth();
},
didUpdate(_prevProps, prevData) {
const { restore } = this.props;
Expand All @@ -59,6 +59,15 @@ Component({
}
},
methods: {
setWindowWidth() {
my.getSystemInfo({
success: (res) => {
this.setData({
windowWidth: res.windowWidth,
});
},
});
},
setBtnWidth() {
my.createSelectorQuery()
.select(`.am-swipe-right-${this.$id}`)
Expand Down
15 changes: 12 additions & 3 deletions src/tabs/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import fmtUnit from '../_util/fmtUnit';

const { windowWidth } = my.getSystemInfoSync();

Component({
props: {
className: '',
Expand Down Expand Up @@ -48,7 +46,7 @@ Component({
elevatorContentTop: 0,
},
data: {
windowWidth,
windowWidth: 0,
tabWidth: 0.25,
autoplay: false,
animation: false,
Expand All @@ -65,6 +63,8 @@ Component({
didMount() {
const { tabs, animation, hasSubTitle, elevator } = this.props;

this.setWindowWidth();

if (hasSubTitle) {
this.setData({
capsule: true,
Expand Down Expand Up @@ -158,6 +158,15 @@ Component({
}
},
methods: {
setWindowWidth() {
my.getSystemInfo({
success: (res) => {
this.setData({
windowWidth: res.windowWidth,
});
},
});
},
getElevatorHeight(tabs) {
for (let i = 0; i < tabs.length; i++) {
my.createSelectorQuery()
Expand Down
Loading

0 comments on commit 2771e39

Please sign in to comment.