Skip to content
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
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface ScrubberProps {
displayValues?: boolean;
}

declare class Scrubber extends Component<ScrubberProps, any> {}
declare class Scrubber extends Component<ScrubberProps, any> {
setValue: (value: number) => void;
}

export = Scrubber;
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default class extends Component {
scrubbingValue: 0,
dimensionWidth: 0,
startingNumberValue: props.value,
value: props.value || 0,
};

this._translateX = new Animated.Value(0);
Expand All @@ -86,6 +87,12 @@ export default class extends Component {
componentWillUnmount() {
this._translateX.removeAllListeners();
}

setValue(value) {
if (typeof value === 'number') {
this.setState({ ...this.state, value });
}
}

scaleUp = () => {
Animated.timing(this.scaleFactor, {
Expand All @@ -105,7 +112,8 @@ export default class extends Component {

_onHandlerStateChange = (event) => {
if (event.nativeEvent.state === State.BEGAN) {
const { totalDuration, value } = this.props;
const { totalDuration } = this.props;
const value = this.props.value || this.state.value;
const currentPercent =
totalDuration !== 0
? Math.min(totalDuration, value) / totalDuration
Expand Down Expand Up @@ -151,7 +159,8 @@ export default class extends Component {

formattedStartingNumber = () => {
const { scrubbing, startingNumberValue } = this.state;
const { value, totalDuration } = this.props;
const { totalDuration } = this.props;
const value = this.props.value || this.state.value;

if (!totalDuration) {
return PLACEHOLDER_DISPLAY_VALUE;
Expand All @@ -161,7 +170,8 @@ export default class extends Component {
};

formattedEndingNumber = () => {
const { value, totalDuration } = this.props;
const { totalDuration } = this.props;
const value = this.props.value || this.state.value;
const { scrubbing, endingNumberValue } = this.state;
const cappedValue = Math.min(totalDuration, value);
const remainingValue = totalDuration - cappedValue;
Expand All @@ -184,7 +194,7 @@ export default class extends Component {
};

onSlidingStart = () => {
if (typeof this.props.onSlide === 'function') {
if (typeof this.props.onSlidingStart === 'function') {
this.props.onSlidingStart();
}
}
Expand Down Expand Up @@ -264,7 +274,6 @@ export default class extends Component {

render() {
const {
value = 0,
bufferedValue = 0,
totalDuration = 1,
trackBackgroundColor = DefaultColors.trackBackgroundColor,
Expand All @@ -274,6 +283,7 @@ export default class extends Component {
displayedValueStyle = { color: DefaultColors.valueColor },
displayValues = true,
} = this.props;
const value = this.props.value || this.state.value;

const { scrubbing, dimensionWidth } = this.state;

Expand Down