admin管理员组文章数量:1419168
I have a specific sliders. How can I style them? I use react-native-slider. Here my code(I modified code from this example):
render() {
const sliderStyle = {
sliderDummy: {
width: 200,
height: 80,
position: 'absolute',
},
sliderReal: {
backgroundColor: colors.primary,
width: (this.state.slideValue / 50) * 200,
height: 80,
borderBottomRightRadius: 100,
borderTopRightRadius: 100
}
}
return (
<View style={styles.container}>
<View style={{overflow: 'hidden'}}>
<View style={{flexDirection: 'row', position: 'absolute'}}>
<View style={sliderStyle.sliderDummy}></View>
<View style={sliderStyle.sliderReal}></View>
</View>
<Slider
style={{width: 200, height: 80}}
minimumValue={0}
maximumValue={50}
value={this.state.slideValue}
onValueChange={(value)=> this.setState({ slideValue: value}) }
maximumTrackTintColor='transparent'
minimumTrackTintColor='transparent'
thumbStyle={styles.thumb}
/>
<Text>{this.state.slideValue}</Text>
</View>
</View>
);
}
}
When I swipe right I have round corners in the middle of track:
But I need something like this:
Where is my mistake? Thanks.
I have a specific sliders. How can I style them? I use react-native-slider. Here my code(I modified code from this example):
render() {
const sliderStyle = {
sliderDummy: {
width: 200,
height: 80,
position: 'absolute',
},
sliderReal: {
backgroundColor: colors.primary,
width: (this.state.slideValue / 50) * 200,
height: 80,
borderBottomRightRadius: 100,
borderTopRightRadius: 100
}
}
return (
<View style={styles.container}>
<View style={{overflow: 'hidden'}}>
<View style={{flexDirection: 'row', position: 'absolute'}}>
<View style={sliderStyle.sliderDummy}></View>
<View style={sliderStyle.sliderReal}></View>
</View>
<Slider
style={{width: 200, height: 80}}
minimumValue={0}
maximumValue={50}
value={this.state.slideValue}
onValueChange={(value)=> this.setState({ slideValue: value}) }
maximumTrackTintColor='transparent'
minimumTrackTintColor='transparent'
thumbStyle={styles.thumb}
/>
<Text>{this.state.slideValue}</Text>
</View>
</View>
);
}
}
When I swipe right I have round corners in the middle of track:
But I need something like this:
Where is my mistake? Thanks.
Share Improve this question asked Feb 18, 2019 at 14:48 KeylorNavasKeylorNavas 1511 gold badge3 silver badges10 bronze badges1 Answer
Reset to default 1I solved this problem easier way than expected. I just set trackStyle(react-native-slider) and this worked like a charm. But now I have another problem, how get slider style track like a "zebra".
render() {
return (
<View style={styles.container}>
<Slider
style={{width: 150, height: 80}}
minimumValue={this.state.min}
maximumValue={this.state.max}
value={this.state.min}
onValueChange={(value)=> this.setState({ slideValue: value}) }
maximumTrackTintColor='transparent'
minimumTrackTintColor={colors.primary}
thumbStyle={styles.thumb}
trackStyle={styles.track}
step={1}
/>
<Text>{this.state.slideValue}</Text>
<Text>min {this.state.min}</Text>
<Text>max {this.state.max}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
thumb: {
width: 50,
height: 80,
backgroundColor: colors.primary,
borderBottomRightRadius: 100,
borderTopRightRadius: 100,
},
track:{
height: 80,
borderBottomRightRadius: 20,
borderTopRightRadius: 20,
}
});
本文标签: javascriptHow to style a Slider on React NativeStack Overflow
版权声明:本文标题:javascript - How to style a Slider on React Native - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745304315a2652553.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论