Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding styles #615

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions package/src/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, {useState} from 'react';
import {
Image,
Platform,
StyleSheet,
AccessibilityActionEvent,
ViewProps,
ViewStyle,
Expand Down Expand Up @@ -73,7 +72,8 @@ type Props = ViewProps &
* Used to style and layout the `Slider`. See `StyleSheet.js` and
* `DeprecatedViewStylePropTypes.js` for more info.
*/
style?: StyleProp<ViewStyle>;
containerStyle?: StyleProp<ViewStyle>;
sliderStyle?: StyleProp<ViewStyle>;

/**
* Write-only property representing the value of the slider.
Expand Down Expand Up @@ -227,11 +227,6 @@ const SliderComponent = (
(_, index) => localProps.minimumValue! + index * step,
);

const defaultStyle =
Platform.OS === 'ios' ? styles.defaultSlideriOS : styles.defaultSlider;
const sliderStyle = {zIndex: 1, width: width};
const style = StyleSheet.compose(props.style, defaultStyle);

const onValueChangeEvent = (event: Event) => {
onValueChange && onValueChange(event.nativeEvent.value);
setCurrentValue(event.nativeEvent.value);
Expand Down Expand Up @@ -287,7 +282,7 @@ const SliderComponent = (
onLayout={(event) => {
setWidth(event.nativeEvent.layout.width);
}}
style={[styles, style, {justifyContent: 'center'}]}>
style={[styles.containerStyle, props.containerStyle]}>
{props.StepMarker || !!props.renderStepNumber ? (
<StepsIndicator
options={options}
Expand All @@ -313,11 +308,7 @@ const SliderComponent = (
: Image.resolveAssetSource(props.thumbImage)
}
ref={forwardedRef}
style={[
sliderStyle,
defaultStyle,
{alignContent: 'center', alignItems: 'center'},
]}
style={[styles.sliderStyle, {width: width}, props.sliderStyle]}
onChange={onValueChangeEvent}
onRNCSliderSlidingStart={onSlidingStartEvent}
onRNCSliderSlidingComplete={onSlidingCompleteEvent}
Expand Down
25 changes: 10 additions & 15 deletions package/src/utils/styles.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import {Platform, StyleSheet} from 'react-native';

export const styles = StyleSheet.create({
containerStyle: {
justifyContent: 'center',
height: Platform.OS === 'ios' ? 40 : undefined,
},
sliderStyle: {
alignContent: 'center',
alignItems: 'center',
zIndex: 1,
height: Platform.OS === 'ios' ? 40 : undefined,
},
stepNumber: {
marginTop: 20,
alignItems: 'center',
position: 'absolute',
},
sliderMainContainer: {zIndex: 1, width: '100%'},
defaultSlideriOS: {
height: 40,
},
defaultSlider: {},
stepsIndicator: {
flex: 1,
flexDirection: 'row',
Expand Down Expand Up @@ -42,14 +47,4 @@ export const styles = StyleSheet.create({
alignItems: 'center',
alignContent: 'center',
},
defaultIndicatorMarked: {
height: 20,
width: 5,
backgroundColor: '#CCCCCC',
},
defaultIndicatorIdle: {
height: 10,
width: 2,
backgroundColor: '#C0C0C0',
},
});
3 changes: 2 additions & 1 deletion package/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ export interface SliderProps
/**
* Used to style and layout the Slider. See StyleSheet.js and ViewStylePropTypes.js for more info.
*/
style?: ReactNative.StyleProp<ReactNative.ViewStyle>;
containerStyle?: ReactNative.StyleProp<ReactNative.ViewStyle>;
sliderStyle?: ReactNative.StyleProp<ReactNative.ViewStyle>;

/**
* Used to locate this view in UI automation tests.
Expand Down
Loading