Comments (16)
Minor tweak - this version:
https://codesandbox.io/s/4303ylv5n9
just adds onEnded
to @sghall's to keep the play/pause buttons in the right state when the video ends.
from react-compound-slider.
Hey there. Yeah, interesting use case. Never tried anything like that before. You also have the "onUpdate" which will give you everything and you need to pick out the cases you care about.
public onUpdate = values => {
this.setState(({ isSeeking }) => {
if (isSeeking) {
return null;
}
this.props.onSeekTo(values[0]);
return { values };
});
};
I think this does what you want it to do. Right?
https://codesandbox.io/s/qz315pn119
from react-compound-slider.
Or actually you just need to call the prop function I think...
public onUpdate = values => {
if (!this.state.isSeeking) {
this.props.onSeekTo(values[0]);
}
};
https://codesandbox.io/s/qz315pn119
from react-compound-slider.
Yes, but when it is an actual video (and not a Javascript Interval) you will get into trouble because onSeekTo
is actually video.currentTime=values[0]
.
from react-compound-slider.
By adding my own onClick slider handler I got it working:
https://codesandbox.io/s/q78wqv12y6
getDerivedStateFromProps(props, state) {
if (!state.isSeeking) {
return {
values: [props.currentTime || 0]
};
}
return null;
}
componentDidUpdate(prevProps, prevState) {
if (prevState.isSeeking && !this.state.isSeeking) {
this.props.onSeekTo(prevState.values[0]);
}
}
onChange = (values: number[]) => {
this.setState({ values });
};
onUpdate = (values: number[]) => {
this.setState({ values });
};
handleSlideStart = () => {
this.setState({ isSeeking: true });
};
handleSlideEnd = () => {
this.setState({ isSeeking: false });
};
handleSliderPress = event => {
const {type} = event
this.setState(
prev => ({ isSeeking: !prev.isSeeking }),
() => {
console.log(type);
}
);
};
from react-compound-slider.
There is another issue, seems like everything I put over or under the slider will only take mouseup
. Maybe the slider is event.preventDefaulting it?
Anyway, if adding onPressDown
and onPressUp
(or something like that) callbacks to the module, this kind of functionality will be easy.
public handleSliderPress = values => {
this.setState(
prev => ({ isSeeking: !prev.isSeeking })
);
}
<Slider onPressDown={this.handleSliderPress} onPressUp={this.handleSliderPress} />
from react-compound-slider.
Yeah, cool. If you want to put together a PR that's great. I'm traveling right now, but go ahead and submit it. Should be able to take a look in a few days. Cheers.
from react-compound-slider.
Cool, I've submitted a PR. My problem can now be solved with this code:
static getDerivedStateFromProps(props, state) {
if (!state.isSeeking) {
return {
values: [props.currentTime || 0]
}
}
return null
}
componentDidUpdate(prevProps, prevState) {
if (prevState.isSeeking && !this.state.isSeeking) {
this.props.onSeekTo(this.state.values[0])
}
}
handleSliderChange = values => {
this.setState({ values })
}
handleSliderUpdate = values => {
this.setState({ values })
}
handleSlideStart = () => {
this.setState({ isSeeking: true })
}
handleSlideEnd = () => {
this.setState({ isSeeking: false })
}
handlePressRail = () => {
this.setState({ isSeeking: true }, () => {
this.setState({ isSeeking: false })
})
}
from react-compound-slider.
Actually I think that according to React standard, onChange should only be called when user changed the input. Just like any "onChange" event is called only when user changes the input and not when the prop was changed. we can leave onUpdate event to be called upon any change
from react-compound-slider.
Took a crack at a video slider to see how it could be done with the current API. Seems pretty good to me...
https://codesandbox.io/s/oqr004j7v9
Thoughts?
from react-compound-slider.
@sghall - yeah, I was also able to do this if everything was in one component. However, I was not able to do it if the UI was supposed to be in one component and the video in another, and that's what I was trying to solve.
from react-compound-slider.
I see. Well, for the slider part, it's just moving it into a separate file like this...
https://codesandbox.io/s/1z51zn6q23
from react-compound-slider.
@sghall - cool, that seems to work fine! I suppose adding the state videoCursor
was the trick (and not directly tie it to video.currentTime
)?
from react-compound-slider.
Yeah, seems to me, you need to track the time in two different places. This is what I hacked together. It seems to work well, but be careful I really don't know much working with videos and had to hit MDN a few times.
EDIT: I said originally that both onUpdate and onChange get called on slide end. That's not right, it just calls onChange here:
react-compound-slider/src/Slider/Slider.js
Line 403 in 7b7d01a
But on click, it calls onUpdate and then onChange:
react-compound-slider/src/Slider/Slider.js
Line 388 in 7b7d01a
So both get called on click and, if you look closely at the sandbox I am exploiting the fact that onUpdate gets called first and then onChange which sets videoCursor to null, etc. So the confusion in getting this to work is understandable. You would have to know this.
from react-compound-slider.
@thunderkid correctly pointed out that the videoCursor is not needed in #47. So this is most up-to-date version with some fixes to the styles etc:
https://codesandbox.io/s/64vz7m7v6z
from react-compound-slider.
Closing this one. I think we got this. Open it back up if there's still an issue here.
from react-compound-slider.
Related Issues (20)
- SVG Handle Example? HOT 1
- airbnb slider in pure js or in jquery
- Tutorial step generates TypeError: children is not a function
- Showing rail in varying color based on tick position HOT 2
- Rounding error with domain that contain decimals HOT 1
- Handle id being sorted
- Handling values and step HOT 2
- Cannot read property 'type' of null error in 3.1.0 HOT 2
- the name of Ticks is undefined HOT 2
- Change in step behavior HOT 4
- Step of 0.01 results in too many decimal places in some generated values HOT 2
- Removing the `d3-array` dependency? HOT 2
- Handle tooltips need number formatting HOT 1
- Make Range slider draggable HOT 7
- Custom mode = same min/max value? HOT 1
- Allow slider to work in popup window by registering event listener with Slider's ownerDocument
- Show track with linear gradient?
- Dragging works incorrectly on wide slider with scrolls HOT 1
- How to avoid "jumping" handles?
- GetEventData function return undefined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-compound-slider.