perf(circle): downgrade to native when sdk version lower than 2.9.0 (#4050)

This commit is contained in:
rex 2021-02-19 15:41:24 +08:00 committed by GitHub
parent c5b4858214
commit f9d067e0e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 12 deletions

View File

@ -1,8 +1,9 @@
import { VantComponent } from '../common/component';
import { BLUE, WHITE } from '../common/color';
import { adaptor } from './canvas';
import { isObj } from '../common/validator';
import { VantComponent } from '../common/component';
import { getSystemInfoSync } from '../common/utils';
import { isObj } from '../common/validator';
import { canIUseCanvas2d } from '../common/version';
import { adaptor } from './canvas';
function format(rate) {
return Math.min(Math.max(rate, 0), 100);
@ -70,7 +71,7 @@ VantComponent({
getContext() {
const { type, size } = this.data;
if (type === '') {
if (type === '' || !canIUseCanvas2d()) {
const ctx = wx.createCanvasContext('van-circle', this);
return Promise.resolve(ctx);
}

View File

@ -27,26 +27,32 @@ function compareVersion(v1, v2) {
return 0;
}
export function canIUseModel() {
function gte(version: string) {
const system = getSystemInfoSync();
return compareVersion(system.SDKVersion, '2.9.3') >= 0;
return compareVersion(system.SDKVersion, version) >= 0;
}
export function canIUseModel() {
return gte('2.9.3');
}
export function canIUseFormFieldButton() {
const system = getSystemInfoSync();
return compareVersion(system.SDKVersion, '2.10.3') >= 0;
return gte('2.10.3');
}
export function canIUseAnimate() {
const system = getSystemInfoSync();
return compareVersion(system.SDKVersion, '2.9.0') >= 0;
return gte('2.9.0');
}
export function canIUseGroupSetData() {
const system = getSystemInfoSync();
return compareVersion(system.SDKVersion, '2.4.0') >= 0;
return gte('2.4.0');
}
export function canIUseNextTick() {
return wx.canIUse('nextTick');
}
export function canIUseCanvas2d() {
return gte('2.9.0');
}