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

TypeError · Cannot read property 'getBoundingClientRect' of null #60

Open
vibdev95 opened this issue Oct 16, 2020 · 7 comments
Open

TypeError · Cannot read property 'getBoundingClientRect' of null #60

vibdev95 opened this issue Oct 16, 2020 · 7 comments

Comments

@vibdev95
Copy link

vibdev95 commented Oct 16, 2020

@alexanderwallin

slider component is having an issue after the recent update version(2.0.0-beta.1)

//node_modules/react-player-controls/dist/components/Slider.js:137:23

var $el = _react.default.createRef();

var bounds = function bounds() {

  return $el.current.getBoundingClientRect(); //error - TypeError · Cannot read property 'getBoundingClientRect' of null
  };

This issue is occurring when we click on the play button and then try to drag the slider

@alexanderwallin
Copy link
Owner

Hi @vibhorme. Could you post your code so that I can take a closer look?

@Donaldzzq
Copy link

Donaldzzq commented Oct 18, 2020

Hi @alexanderwallin I got this bug too. Here is my code.

import React, { Component } from "react";
import { Slider, Direction, FormattedTime } from "react-player-controls";
import {
  FastForward,
  FastRewind,
  Fullscreen,
  PlayArrow,
  Pause,
  SkipNext,
  SkipPrevious,
} from "@material-ui/icons";

const GREEN = "#72d687";

// A colored bar that will represent the current value
const SliderBar = ({ direction, value, style }) => (
  <div
    style={Object.assign(
      {},
      {
        position: "absolute",
        background: "rgba(196, 196, 196, 0.2)",
        borderRadius: 4,
      },
      {
        top: 0,
        bottom: 0,
        left: 0,
        width: `${value * 100}%`,
      },
      style
    )}
  />
);

// A handle to indicate the current value
const SliderHandle = ({ direction, value, style }) => (
  <div
    style={Object.assign(
      {},
      {
        position: "absolute",
        width: 16,
        height: 16,
        background: GREEN,
        borderRadius: "100%",
        transform: "scale(1)",
        transition: "transform 0.2s",
        "&:hover": {
          transform: "scale(1.3)",
        },
      },
      {
        top: 0,
        left: `${value * 100}%`,
        marginTop: -4,
        marginLeft: -8,
      },
      style
    )}
  />
);

export default class PlayerControl extends Component {
  state = {
    isPlaying: false,
    value: 0,
    lastValueStart: 0,
    lastValueEnd: 0,
    lastIntent: 0,
    lastIntentStart: 0,
    lastIntentEndCount: 0,
  };
  handleVideoPlay = () => {
    this.setState({ isPlaying: true });
  };
  handleVideoStop = () => {
    this.setState({ isPlaying: false });
  };
  setValue = (newValue) => {
    // console.log(newValue);
    this.setState({ value: newValue });
  };
  onDragEnd = (newValue) => {
    // console.log("onDragEnd: ", newValue);
    this.setState({ value: newValue });
  };
  render() {
    const { isPlaying, value } = this.state;
    const duration = 600;

    return (
      <div className="player-control">
        <div className="control-icons">
          {isPlaying ? (
            <div>
              <SkipPrevious className="icon" />
              <FastRewind width={14} height={14} className="icon" />
              <Pause
                width={14}
                height={14}
                className="icon"
                onClick={this.handleVideoStop}
              />
              <FastForward width={14} height={14} className="icon" />
              <SkipNext width={14} height={14} className="icon" />
            </div>
          ) : (
            <PlayArrow
              width={14}
              height={14}
              className="icon"
              onClick={this.handleVideoPlay}
            />
          )}
        </div>
        <div className="slider">
          <Slider
          
            direction={Direction.HORIZONTAL}
            onChange={this.setValue}
            onChangeStart={(startValue) =>
              this.setState(() => ({ lastValueStart: startValue }))
            }
            onChangeEnd={this.onDragEnd}
            onIntent={(intent) => this.setState(() => ({ lastIntent: intent }))}
            onIntentStart={(intent) =>
              this.setState(() => ({ lastIntentStart: intent }))
            }
            onIntentEnd={() =>
              this.setState(() => ({
                lastIntentEndCount: this.state.lastIntentEndCount + 1,
              }))
            }
            style={{
              width: "80vw",
              height: 6,
              borderRadius: 2,
              background: "rgba(196, 196, 196, 0.2)",
              //   transition: "width 0.1s",
              cursor: "pointer",
            }}
          >
            <SliderBar
              direction={Direction.HORIZONTAL}
              value={1}
              style={{ background: "rgba(196, 196, 196, 0.2)" }}
            />
            <SliderHandle
              direction={Direction.HORIZONTAL}
              value={value}
              style={{ background: "#52ABEC" }}
            />
          </Slider>
        </div>
        <FormattedTime numSeconds={duration} className="period" />
        <Fullscreen className="full-screen" />
      </div>
    );
  }
}

@ericqt
Copy link

ericqt commented Nov 12, 2020

I'm also getting this error when I click on the slider several times.

@Donaldzzq
Copy link

I'm also getting this error when I click on the slider several times.

I am using 1.1.0 to avoid this issue

@ericqt
Copy link

ericqt commented Nov 14, 2020

I'm also getting this error when I click on the slider several times.

I am using 1.1.0 to avoid this issue

I wonder if this can be fixed by upgrading the downstream dependency of react-use-gesture since it seems like this problem is most likely coming from that package

@alexanderwallin
Copy link
Owner

I made a bare minimum app based on @Donaldzzq's code sample above and tested it in Chrome, Opera, Safari and Firefox, and could not replicate the issue. If anyone could post a reproducible repo that would be great!

@hoangvu12
Copy link

It only happens in 2.0.0beta, I assume it is mobile drag problem.

screen-capture-_39_.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants