Skip to content

Commit 4c90030

Browse files
authored
fix(Slider): 滑块输入条 thumbSize属性没有效果, 滑块输入条 thumbSize 设置很大时然后使用 shownThumb=false 输入条拉不满 (#234 # 233) (#236)
* 编写选项卡组件 * 类型名称请调整,添加组件文档在网站上展示 * #162修复报错 * fix:#162修复报错 * SpeedDial 悬浮标记 * 优化类型 * feat(ActionSheet): Add new component. * fix: ActionSheet 实例优化,组件优化 * feat(SearchInputBar): Add new component. * feat(Pagination): Add new component. * fix(Tooltip): 修复cloud弹出元素位置问题 * doc(Drawer): Update README.md * doc: Update README.md * fix(Rating): Rating 评分组件 使用繁琐(#244) * fix(Rating): Rating 评分组件 使用繁琐(#244) * fix(Slider): 滑块输入条 thumbSize属性没有效果, 滑块输入条 thumbSize 设置很大时然后使用 shownThumb=false 效果如下 (#234 # 233) * fix(Slider): 滑块输入条 thumbSize属性没有效果, 滑块输入条 thumbSize 设置很大时然后使用 shownThumb=false 输入条拉不满 (#234 # 233)
1 parent 0890b76 commit 4c90030

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

example/examples/src/routes/Slider/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default class SliderView extends React.Component<
4444
<Slider
4545
value={this.state.sliderValue as number}
4646
onChange={this.handleSliderChange}
47+
thumbSize={{width: 60, height: 30}}
4748
/>
4849
</WingBlank>
4950
<WingBlank>

packages/core/src/Slider/index.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ export default class Slider extends Component<SliderProps, SliderState> {
149149
}
150150
getThumbLeft(value: number) {
151151
const ratio = (value - this.props.minValue!) / (this.props.maxValue! - this.props.minValue!);
152-
return ratio * (this.state.containerSize.width - this.state.thumbSize.width);
152+
if (this.props.shownThumb) {
153+
return ratio * (this.state.containerSize.width - this.state.thumbSize.width);
154+
}
155+
return ratio * this.state.containerSize.width;
153156
}
154157
getCurrentValue = () => (this.state.value as any).__getValue();
155158
handlePanResponderGrant = () => {
@@ -174,8 +177,11 @@ export default class Slider extends Component<SliderProps, SliderState> {
174177
this.props.onChange!(this.getCurrentValue());
175178
};
176179
getValue(gestureState: PanResponderGestureState) {
177-
const { vertical, minValue, maxValue } = this.props;
178-
const length = this.state.containerSize.width - this.state.thumbSize.width;
180+
const { vertical, minValue, maxValue, shownThumb } = this.props;
181+
let length = this.state.containerSize.width - this.state.thumbSize.width;
182+
if (!shownThumb) {
183+
length = this.state.containerSize.width;
184+
}
179185
const thumbLeft = this._previousLeft + (vertical ? gestureState.dy : gestureState.dx);
180186
const ratio = thumbLeft / length;
181187
if (this.props.step) {
@@ -216,10 +222,12 @@ export default class Slider extends Component<SliderProps, SliderState> {
216222
} = { position: 'absolute' };
217223

218224
if (this.props.vertical) {
219-
minimumTrackStyle.height = Animated.add(thumbStart, thumbSize.height / 2);
225+
minimumTrackStyle.height = Animated.add(thumbStart, 0);
226+
// minimumTrackStyle.height = Animated.add(thumbStart, thumbSize.height / 2);
220227
minimumTrackStyle.marginLeft = -trackSize.width;
221228
} else {
222-
minimumTrackStyle.width = Animated.add(thumbStart, thumbSize.width / 2);
229+
minimumTrackStyle.width = Animated.add(thumbStart, 0);
230+
// minimumTrackStyle.width = Animated.add(thumbStart, thumbSize.width / 2);
223231
minimumTrackStyle.marginTop = -trackSize.height;
224232
}
225233
return minimumTrackStyle;
@@ -271,9 +279,13 @@ export default class Slider extends Component<SliderProps, SliderState> {
271279
} = this.props;
272280
const { value, thumbSize, containerSize } = this.state;
273281
const touchOverflowStyle = {} as ViewStyle;
282+
let outputRange = containerSize.width;
283+
if (shownThumb) {
284+
outputRange = containerSize.width - thumbSize.width;
285+
}
274286
const thumbStart = value.interpolate({
275287
inputRange: [minValue!, maxValue!],
276-
outputRange: [0, containerSize.width - thumbSize.width],
288+
outputRange: [0, outputRange],
277289
// extrapolate: 'clamp',
278290
});
279291
const minimumTrackStyle = {
@@ -325,6 +337,11 @@ export default class Slider extends Component<SliderProps, SliderState> {
325337
transform: [...this.getThumbPositionStyles(thumbStart), ...thumbStyleTransform],
326338
...valueVisibleStyle,
327339
},
340+
{
341+
width: thumbSize.width,
342+
height: thumbSize.height,
343+
borderRadius: thumbSize.width / 2,
344+
},
328345
])}
329346
/>
330347
)}

0 commit comments

Comments
 (0)