Skip to content

Commit abfdc03

Browse files
committed
feat: 解决无法修改背景色问题
1 parent a404eb4 commit abfdc03

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

packages/mpx-cube-ui/src/components/switch/index.mpx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
wx:class="{{ switchClass }}"
44
bindtap="toggleSwitch"
55
animation="{{ switchAnimationData }}"
6+
wx:style="{{ swithBGClass }}"
67
>
78
<view
89
class="cube-switch-handle"

packages/mpx-cube-ui/src/components/switch/rn-mixin.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ if (__mpx_mode__ === 'ios' || __mpx_mode__ === 'android') {
1919
lifetimes: {
2020
created() {
2121
this.ANIMATION_PRESET = {
22-
'cube-switch-on': (animationOptions) => {
22+
'cube-switch-BGC': (animationOptions) => {
2323
const animation = this.maskAnimation || (this.maskAnimation = mpx.createAnimation({ ...animationOptions }))
2424
if (this.isOn) {
25-
animation.backgroundColor('#FF6435').step()
25+
const onBGC = this.switchOnGBC || '#FF6435'
26+
animation.backgroundColor(onBGC).step()
2627
} else {
27-
animation.backgroundColor('#EAEAEA').step()
28+
const defaultBGC = this.switchDefaultGBC || '#EAEAEA'
29+
animation.backgroundColor(defaultBGC).step()
2830
}
2931
this.switchAnimationData = animation.export()
3032
},
31-
'cube-switch-handle-on': (animationOptions) => {
33+
'cube-switch-left': (animationOptions) => {
3234
const animation = this.maskAnimation || (this.maskAnimation = mpx.createAnimation({ ...animationOptions }))
3335
if (this.isOn) {
3436
animation.left(18).step()

packages/mpx-cube-ui/src/components/switch/switch.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ createComponent({
1212
type: Boolean,
1313
value: false
1414
},
15+
switchDefaultGBC: {
16+
type: String,
17+
value: ''
18+
},
19+
switchOnGBC: {
20+
type: String,
21+
value: ''
22+
},
1523
/**
1624
* @description 是否禁用
1725
* @optional true/false
@@ -31,6 +39,22 @@ createComponent({
3139
'cube-switch-on': this.isOn,
3240
[`cube-switch-${this.themeType}`]: this.themeType
3341
}
42+
},
43+
swithBGClass() {
44+
if (__mpx_mode__ === 'ios' || __mpx_mode__ === 'android') {
45+
return {}
46+
}
47+
if (this.isOn && this.switchOnGBC) {
48+
return {
49+
backgroundColor: this.switchOnGBC
50+
}
51+
} else if (!this.isOn && this.switchDefaultGBC) {
52+
return {
53+
backgroundColor: this.switchDefaultGBC
54+
}
55+
} else {
56+
return {}
57+
}
3458
}
3559
},
3660
watch: {

0 commit comments

Comments
 (0)