Skip to content

Commit 24b95a1

Browse files
committed
fix: 条件编译
1 parent 393bd0a commit 24b95a1

4 files changed

Lines changed: 55 additions & 9 deletions

File tree

packages/mpx-cube-ui/src/components/slider/css.rn.styl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
position: relative
66
display: flex
77
align-items: center
8-
background: blue
98

109
.cube-slider-tab-area
1110
flex: 1 0 auto

packages/mpx-cube-ui/src/components/slider/gesture.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { View } from 'react-native'
2+
import { runOnJS } from 'react-native-reanimated'
23
import { createElement, useMemo, Children } from 'react'
34
import { GestureDetector, Gesture } from 'react-native-gesture-handler'
4-
import { runOnJS } from 'react-native-reanimated';
55

66
const Slider = ({
77
ontouchstart,

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

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<template>
22
<view
33
wx:class="{{ sliderClass }}"
4-
wx:style="{{ { ...containerStyle, ...tabAreaStyle } }}"
4+
wx:style="{{ containerStyle }}"
55
>
66
<gesture
7+
wx:if="{{ __mpx_mode__ === 'android' || __mpx_mode__ === 'ios' || __mpx_mode__ === 'harmony' }}"
78
ontouchstart="{{startHandler}}"
89
ontouchmove="{{moveHandler}}"
910
ontonouchend="{{endHandler}}"
@@ -35,6 +36,36 @@
3536
</view>
3637
</view>
3738
</gesture>
39+
<view
40+
wx:ref
41+
wx:else
42+
class="cube-slider-tab-area"
43+
wx:style="{{ tabAreaStyle }}"
44+
bind:tap="onClick"
45+
>
46+
<!-- 滑块儿容器 -->
47+
<view
48+
class="cube-slider-handle"
49+
wx:style="{{ handleStyle }}"
50+
capture-catch:touchstart="startHandler"
51+
capture-catch:touchmove="moveHandler"
52+
capture-catch:touchend="endHandler"
53+
>
54+
<!-- 滑块儿 -->
55+
<view class="cube-slider-thumb-custom" wx:style="{{ { display: customContent ? '' : 'none', ...thumbStyle } }}">
56+
<!-- 自定义滑块儿 -->
57+
<slot></slot>
58+
</view>
59+
<view
60+
wx:if="{{!customContent}}"
61+
class="cube-slider-thumb"
62+
wx:style="{{ thumbStyle }}"
63+
></view>
64+
</view>
65+
<view class="cube-slider-track" wx:style="{{ trackStyle }}">
66+
<view class="cube-slider-step" wx:style="{{ stepStyle }}"></view>
67+
</view>
68+
</view>
3869
<view wx:if="{{ showValueLable }}" class="cube-slider-value">
3970
<text
4071
numberOfLines@_ios|_android|_harmony="{{1}}"
@@ -54,12 +85,20 @@
5485
/* @mpx-endif */
5586
</style>
5687

57-
<script type="application/json">
58-
{
88+
<script name="json">
89+
const isNative = __mpx_mode__ === 'ios' || __mpx_mode__ === 'android' || __mpx_mode__ === 'harmony'
90+
const base = {
5991
"styleIsolation": "shared",
60-
"component": true,
61-
"usingComponents": {
62-
"gesture": "./gesture.tsx"
92+
"component": true
93+
}
94+
if (isNative) {
95+
module.exports = {
96+
...base,
97+
"usingComponents": {
98+
"gesture": "./gesture.tsx"
99+
}
63100
}
101+
} else {
102+
module.exports = base
64103
}
65104
</script>

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,18 @@ createComponent({
139139
return this['show-value'] || this.showValue
140140
},
141141
containerStyle() {
142-
return {
142+
const baseStyle = {
143143
marginLeft: `${this._blockSize / 2 + 4}px`,
144144
marginRight: `${this._blockSize / 2 + 4}px`
145145
}
146+
const isNative = __mpx_mode__ === 'ios' || __mpx_mode__ === 'android' || __mpx_mode__ === 'harmony'
147+
if (isNative) {
148+
return {
149+
...baseStyle,
150+
...this.tabAreaStyle
151+
}
152+
}
153+
return baseStyle
146154
},
147155
tabAreaStyle() {
148156
const minH = Math.max(12, this._blockSize) / 2

0 commit comments

Comments
 (0)