├── .editorconfig
├── .gitattributes
├── .gitignore
├── .husky
├── .gitignore
├── .npmignore
├── commit-msg
└── pre-commit
├── .yarnrc
├── API.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── babel.config.js
├── example
├── app.json
├── babel.config.js
├── index.js
├── metro.config.js
├── package.json
├── src
│ └── App.tsx
├── tsconfig.json
├── webpack.config.js
└── yarn.lock
├── package.json
├── scripts
└── bootstrap.js
├── src
├── __tests__
│ └── index.test.tsx
├── components
│ ├── ControlFullScreen.tsx
│ ├── ControlSlider.tsx
│ ├── ControlThumb.tsx
│ ├── ControlTouchable.tsx
│ ├── ControlVideoState.tsx
│ ├── CurrentTime.tsx
│ ├── ReText.tsx
│ ├── VideoControls.tsx
│ ├── defaultProps.tsx
│ └── types.ts
├── context
│ └── ControlsVisibility.tsx
├── hooks
│ ├── useControlSlider.ts
│ ├── useControlThumb.ts
│ ├── useControlsVideoState.ts
│ ├── useLayout.ts
│ ├── useLongPressGesture.ts
│ ├── usePinchGesture.ts
│ ├── useTapGesture.ts
│ └── useTimeFromThumb.ts
├── index.tsx
└── utils
│ └── time.ts
├── tsconfig.build.json
├── tsconfig.json
└── yarn.lock
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 | [*]
8 |
9 | indent_style = space
10 | indent_size = 2
11 |
12 | end_of_line = lf
13 | charset = utf-8
14 | trim_trailing_whitespace = true
15 | insert_final_newline = true
16 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 | # specific for windows script files
3 | *.bat text eol=crlf
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # XDE
6 | .expo/
7 |
8 | # VSCode
9 | .vscode/
10 | jsconfig.json
11 |
12 | # Xcode
13 | #
14 | build/
15 | *.pbxuser
16 | !default.pbxuser
17 | *.mode1v3
18 | !default.mode1v3
19 | *.mode2v3
20 | !default.mode2v3
21 | *.perspectivev3
22 | !default.perspectivev3
23 | xcuserdata
24 | *.xccheckout
25 | *.moved-aside
26 | DerivedData
27 | *.hmap
28 | *.ipa
29 | *.xcuserstate
30 | project.xcworkspace
31 |
32 | # Android/IJ
33 | #
34 | .classpath
35 | .cxx
36 | .gradle
37 | .idea
38 | .project
39 | .settings
40 | local.properties
41 | android.iml
42 |
43 | # Cocoapods
44 | #
45 | example/ios/Pods
46 |
47 | # node.js
48 | #
49 | node_modules/
50 | npm-debug.log
51 | yarn-debug.log
52 | yarn-error.log
53 |
54 | # BUCK
55 | buck-out/
56 | \.buckd/
57 | android/app/libs
58 | android/keystores/debug.keystore
59 |
60 | # Expo
61 | .expo/*
62 |
63 | # generated by bob
64 | lib/
65 |
--------------------------------------------------------------------------------
/.husky/.gitignore:
--------------------------------------------------------------------------------
1 | _
2 |
--------------------------------------------------------------------------------
/.husky/.npmignore:
--------------------------------------------------------------------------------
1 | _
2 |
--------------------------------------------------------------------------------
/.husky/commit-msg:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | yarn commitlint -E HUSKY_GIT_PARAMS
5 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | yarn lint && yarn typescript
5 |
--------------------------------------------------------------------------------
/.yarnrc:
--------------------------------------------------------------------------------
1 | # Override Yarn command so we can automatically setup the repo on running `yarn`
2 |
3 | yarn-path "scripts/bootstrap.js"
4 |
--------------------------------------------------------------------------------
/API.md:
--------------------------------------------------------------------------------
1 | # [Components list](#components)
2 |
3 | - [VideoControls](#videocontrols)
4 | - [ControlSlider](#controlslider)
5 | - [ControlThumb](#controlthumb)
6 | - [ControlVideoState](#controlvideostate)
7 | - [ControlFullScreen](#controlfullscreen)
8 | - [ControlTouchable](#controltouchable)
9 |
10 | # [Hooks list](#hooks)
11 |
12 | - [useControlSlider](#usecontrolslider)
13 | - [useControlsVideoState](#usecontrolvideostate)
14 | - [useControlFullScreen](#usecontrolfullscreen)
15 | - [useControlThumb](#usecontrolthumb)
16 | - [useLayout](#uselayout)
17 | - [useTapGesture / useLongPressGesture](#uselongpressgesture--usetapgesture)
18 | - [useTimeFromThumb](#usetimefromthumb)
19 | - [useControlsVisibility](#usecontrolsvisibility)
20 | - [usePinchGesture](#usepinchgesture)
21 |
22 | # Components
23 |
24 | ## VideoControls
25 |
26 | This is the main component that will render your player and the controls on it. You can pass children if you need to render custom views that are not handled by the lib (for example a video title).
27 |
28 | #### videoElement (required)
29 |
30 | A React element that renders the video player.
31 |
32 | #### initialVisible (optional, default `true`)
33 |
34 | If true, the controls will be visible during the initial render.
35 |
36 | #### autoHideAfterDuration (optional, default `3000`)
37 |
38 | Duration in ms after which the controls automatically hide.
39 |
40 | #### components (optional)
41 |
42 | Map of components that will be used to render some parts of the controls (slider, state controls for example). You can pass the following keys:
43 |
44 | - `slider`: The slider that renders at the bottom of the player. Defaults to [ControlSlider](#controlslider).
45 | - `videoState`: The state controls that render at the center of the player. Defaults to [ControlVideoState](#controlvideostate).
46 |
47 | Example:
48 |
49 | ```js
50 | }
56 | />
57 | ```
58 |
59 | #### componentsProps (optional)
60 |
61 | Map of props to pass to the components used to render the controls (similar to the `components` prop).
62 |
63 | Just like the `components` prop, it allows the following keys:
64 |
65 | - `slider` (see [ControlSlider](#controlslider)):
66 | - `videoState` (see [ControlVideoState](#controlvideostate))
67 |
68 | Example:
69 |
70 | ```js
71 | }
78 | />
79 | ```
80 |
81 | #### onFastForward (optional)
82 |
83 | Called when the user double taps on the right side of the controls.
84 |
85 | #### onFastRewind (optional)
86 |
87 | Called when the user double taps on the left side of the controls.
88 |
89 | #### videoStateContainerStyle (optional)
90 |
91 | Style to apply to the container that contains the state controls. Useful if you want to position the state controls differently, for example if you want to make them full width.
92 |
93 | #### containerStyle (optional)
94 |
95 | Style applied to the controls container.
96 |
97 | #### onZoomIn (optional)
98 |
99 | Function called when zooming in the video with a pinch gesture.
100 |
101 | #### onZoomOut (optional)
102 |
103 | Function called when zooming out the video with a pinch gesture.
104 |
105 | ### autoDismiss (optional, default `true`)
106 |
107 | Boolean indicating the auto dismiss of the controls.
108 |
109 | ### enableDismissOnTap (optional, default `true`)
110 |
111 | Boolean indicating if the controls should be dismissed when the user taps on the controls overlay.
112 |
113 | ---
114 |
115 | ## ControlSlider
116 |
117 | The control slider is a component that will render the progress bar, the current time, the total duration and a fullscreen button if provided.
118 |
119 | #### totalDuration (required)
120 |
121 | The total duration of the video
122 |
123 | #### onSeek (required)
124 |
125 | Function called when the user seeks the video from the slider's thumb. It receives the time in second as an argument.
126 |
127 | #### activeColor (optional, default `white`)
128 |
129 | Color for the past part (left side of the thumb) of the progress bar.
130 |
131 | #### inactiveColor (optional, default `#aaa`)
132 |
133 | Color for the future part (right side of the thumb) of the progress bar.
134 |
135 | #### playableColor (optional, default `#ccc`)
136 |
137 | Color for the future part (right side of the thumb) of the progress bar that goes until the playable part of the video.
138 |
139 | #### thumb (optional)
140 |
141 | React element that will render the thumb of the slider. Defaults to [ControlThumb](#controlthumb).
142 |
143 | #### renderTotalDuration (optional)
144 |
145 | Function that receives the total duration (in seconds) of the video. Returns a React element. Defaults to a white text formatted with minutes:seconds.
146 |
147 | #### renderCurrentTime (optional)
148 |
149 | Function that receives the current time (in seconds) of the video. Returns a React element. Defaults to a white text formatted with minutes:seconds.
150 |
151 | It is recommended to give a fixed width to its container so that the slider layout is not affected by the width of the text.
152 |
153 | _Note: the argument is a [reanimated SharedValue](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/shared-values/). To render it as a text, you can use the CurrentTime component._
154 |
155 | #### sliderStyle (optional)
156 |
157 | Style applied to the slider. Can be useful to set a height.
158 |
159 | #### sliderContainerStyle (optional)
160 |
161 | Style applied to the slider container, which includes the current time and total duration.
162 |
163 | #### radius (optional)
164 |
165 | Border radius for the slider element and inner elements (playable part, played part).
166 |
167 | #### fullScreenElement (optional)
168 |
169 | React element that will render the fullscreen button. Defaults to [ControlFullScreen](#controlfullscreen).
170 |
171 | #### timeSharedValue (optional)
172 |
173 | Reanimated shared value that allows you to keep track of the current progress time.
174 |
175 | #### thumbSharedValue (optional)
176 |
177 | Reanimated shared value that allows you to keep track of the current thumb progress.
178 |
179 | #### thumbSimultaneousGestures (optional)
180 |
181 | Extra gesture handlers (from [react-native-gesture-handler](https://docs.swmansion.com/react-native-gesture-handler/)) that runs simultaneously with the main thumb gesture handler which handles its translation. Useful if you need to apply a scale effect on the thumb while its pressed.
182 |
183 | #### onSliderLayout (optional)
184 |
185 | Layout function that is applied to the slider element.
186 |
187 | #### thumbHitSlop (optional, default `20`)
188 |
189 | Hit slop for the thumb element. It accepts a number or an insets object, similar to the [react-native hitSlop prop](https://reactnative.dev/docs/touchablewithoutfeedback#hitslop). For a number, the value is applied to all edges.
190 |
191 | #### setCurrentTime (method)
192 |
193 | Set the current time of the video.
194 |
195 | #### setPlayableTime (method)
196 |
197 | Set the playable time of the video.
198 |
199 | ---
200 |
201 | ## ControlThumb
202 |
203 | #### color (optional, default `white`)
204 |
205 | Color of the thumb.
206 |
207 | ---
208 |
209 | ## ControlVideoState
210 |
211 | #### onPlay (required)
212 |
213 | Function called when the user presses the play button.
214 |
215 | #### onPause (required)
216 |
217 | Function called when the user presses the pause button.
218 |
219 | #### onForward (optional)
220 |
221 | Function called when the user presses the forward button.
222 |
223 | #### onRewind (optional)
224 |
225 | Function called when the user presses the rewind button.
226 |
227 | #### isPlaying (required)
228 |
229 | Boolean indicating if the video is playing or not.
230 |
231 | #### components (required)
232 |
233 | Map of components used to render each part of the video state controls. You can pass the following keys:
234 |
235 | - `play`: The play icon.
236 | - `pause`: The pause icon.
237 | - `forward`: The forward icon.
238 | - `rewind`: The rewind icon.
239 |
240 | All those components receive the following props:
241 |
242 | - `isPressed`: boolean indicating the the touchable is being pressed or not. Useful to trigger an animation or apply different style.
243 |
244 | #### spacing (optional, default `10`)
245 |
246 | Spacing applied between each controls.
247 |
248 | It also accepts a string (`space-between` or `space-around`). In that case, the prop is applied to a `justifyContent` style.
249 |
250 | ---
251 |
252 | ## ControlFullScreen
253 |
254 | The ControlFullScreen component renders a touchable icon depending if the player is in full screen or not.
255 |
256 | #### isFullScreen (required)
257 |
258 | Boolean indicating if the player is in fullscreen or not
259 |
260 | #### components (required)
261 |
262 | Map of components used to render each part of the fullscreen button. You can pass the following keys:
263 |
264 | - `fullScreen`: The fullscreen icon.
265 | - `exitFullScreen`: The exit fullscreen icon.
266 |
267 | They receive no prop.
268 |
269 | #### onToggleFullScreen (required)
270 |
271 | Function called when the user presses the fullscreen (or exit fullscreen) button.
272 |
273 | ---
274 |
275 | ## ControlTouchable
276 |
277 | The ControlTouchable component renders a tap gesture handler. You should use it if you want to add custom touchables to the controls.
278 |
279 | #### numberOfTaps (optional, default `1`)
280 |
281 | Number of taps required to trigger the onPress function.
282 |
283 | #### onPress (optional)
284 |
285 | Function called when the gesture has completed
286 |
287 | #### maxDuration (optional, in ms, default `500`)
288 |
289 | Maximum duration of the tap gesture.
290 |
291 | #### children
292 |
293 | A React element or a function. The function will receive an object as an argument, containing the following keys:
294 |
295 | - `pressed`: boolean indicating if the touchable is being pressed or not.
296 |
297 | ---
298 |
299 | # Hooks
300 |
301 | ## useControlSlider
302 |
303 | Handles shared value for the current time and the playable time. It also handles the styling for the active and playable parts of the progress bar.
304 |
305 | It accepts an object with the following keys:
306 |
307 | - `totalDuration` _(required)_ : the total duration of the video.
308 | - `progressLayout` _(required)_ : the layout of the slider element.
309 | - `timeSharedValue` _(optional)_ : See [here](#timesharedvalue-optional)
310 |
311 | Returns:
312 |
313 | - `setCurrentTime`: function to update the current time shared value.
314 | - `setPlayableTime`: function to update the playable time shared value.
315 | - `timeValue`: shared value for the current time of the video.
316 | - `playableTimeValue`: shared value for the playable time of the video.
317 | - `activeViewStyle`: style for the active part of the progress bar.
318 | - `playableTimeStyle`: style for the playable part of the progress bar.
319 |
320 | ## useControlsVideoState
321 |
322 | Handles the interaction between the video state controls and the visibility of the controls. If a button is pressed, the timer to hide the controls is reset. See [visibility](#visibility).
323 |
324 | It accepts an object with the following keys:
325 |
326 | - `onPlay` _(required)_ : function called when the user presses the play button.
327 | - `onPause` _(required)_ : function called when the user presses the pause button.
328 | - `onForward` _(optional)_ : function called when the user presses the forward button.
329 | - `onRewind` _(optional)_ : function called when the user presses the rewind button.
330 |
331 | Returns the same object as the one passed to the hook, with an extra:
332 |
333 | - `setPressedButton`: Function to indicate which button is being pressed. This allows to not hide the controls while a button is being pressed. It accepts 2 arguments: a string with the name of the button and a boolean indicating if the button is being pressed.
334 |
335 | ## useControlThumb
336 |
337 | Handles the thumb gesture. It accepts an object with the following keys:
338 |
339 | - `progressLayout` _(required)_ : the layout of the slider element.
340 | - `onGestureEnd` _(required)_ : function called when the gesture has ended. Receives the time in seconds as parameter.
341 | - `totalDuration` _(required)_ : the total duration of the video.
342 | - `thumbSharedValue` _(optional)_ : See [here](#timesharedvalue-optional)
343 | - `hitSlop` _(optional, default `20`)_ : See [here](#thumbhitslop-optional)
344 | - `timeSharedValue` _(required)_ : the current time as a shared value.
345 |
346 | Returns:
347 |
348 | - `thumbGestureHandler` : the gesture handler for the thumb
349 | - `thumbValue`: the thumb translation as a shared value
350 | - `updateThumbFromTime`: function to update the thumb position from a time in seconds.
351 |
352 | ## useLayout
353 |
354 | Handles a view layout. Returns a tuple with the layout and a function to update the layout.
355 |
356 | Example:
357 |
358 | ```js
359 | const [layout, onLayout] = useLayout();
360 |
361 | return ;
362 | ```
363 |
364 | ## useLongPressGesture / useTapGesture
365 |
366 | Both hooks handle a tap gesture or a long press gesture. They accept an object with the following keys:
367 |
368 | - `onBegin` _(optional)_ : function called when the gesture has begun.
369 | - `onEnd` _(optional)_ : function called when the gesture has ended.
370 | - `onTouchesUp` _(optional)_ : function called when the finger is lifted.
371 | - `onTouchesDown` _(optional)_ : function called when the finger is placed on the screen.
372 | - `onTouchesCancelled` _(optional)_ : function called when the finger stops being tracked.
373 |
374 | Returns a [Tap Gesture](https://docs.swmansion.com/react-native-gesture-handler/docs/api/gestures/tap-gesture) or a [LongPress Gesture](https://docs.swmansion.com/react-native-gesture-handler/docs/api/gestures/long-press-gesture).
375 |
376 | ## useTimeFromThumb
377 |
378 | Handles the time from the thumb position. It accepts an object with the following keys:
379 |
380 | - `thumbValue` _(required)_ : the shared value for the thumb position.
381 | - `totalDuration` _(required)_ : the total duration of the video in seconds.
382 | - `progressLayout` _(required)_ : the layout of the slider element.
383 |
384 | Returns an object with the following keys:
385 |
386 | - `time`: the time in seconds from the thumb position.
387 |
388 | ## useControlsVisibility
389 |
390 | Returns the context values handled by the visibility context. See [visibility](#visibility).
391 |
392 | ## usePinchGesture
393 |
394 | Handles a pinch gesture. It accepts an object with the following keys:
395 |
396 | - `onPinchIn` _(required)_ : function called when the users pinches with the fingers from the outside to the inside
397 | - `onPinchOut` _(required)_ : function called when the users pinches with the fingers from the inside to the outside
398 |
399 | Returns a [Pinch Gesture](https://docs.swmansion.com/react-native-gesture-handler/docs/api/gestures/pinch-gesture)
400 |
401 | ---
402 |
403 | # Visibility
404 |
405 | The visibility of the controls is handled by a context, which holds a timeout that will start, stop or reset depending on the actions of the user: press on a button, trigger the slider's thumb, etc.
406 |
407 | This context is rendered by the [VideoControls](#videocontrols) component. So if you need to access this context, you should render your component as a children of `VideoControls`.
408 |
409 | The context holds the following values:
410 |
411 | - `resetVisibilityTimer` : function that restarts the timer
412 | - `startTimer` : function that starts the timer
413 | - `stopTimer` : function that stops the timer
414 | - `isPlaying` : boolean indicating if the video is playing or not
415 |
416 | ---
417 |
418 | # Methods
419 |
420 | You can access the following methods thanks to a ref to the `VideoControls` component:
421 |
422 | - `toggleVisible`: function to toggle the visibility of the controls
423 | - `setVisible`: function to set the visibility of the controls. Takes a boolean as an argument.
424 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project.
4 |
5 | ## Development workflow
6 |
7 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
8 |
9 | ```sh
10 | yarn
11 | ```
12 |
13 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development.
14 |
15 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app.
16 |
17 | To start the packager:
18 |
19 | ```sh
20 | yarn example start
21 | ```
22 |
23 | To run the example app on Android:
24 |
25 | ```sh
26 | yarn example android
27 | ```
28 |
29 | To run the example app on iOS:
30 |
31 | ```sh
32 | yarn example ios
33 | ```
34 |
35 | To run the example app on Web:
36 |
37 | ```sh
38 | yarn example web
39 | ```
40 |
41 | Make sure your code passes TypeScript and ESLint. Run the following to verify:
42 |
43 | ```sh
44 | yarn typescript
45 | yarn lint
46 | ```
47 |
48 | To fix formatting errors, run the following:
49 |
50 | ```sh
51 | yarn lint --fix
52 | ```
53 |
54 | Remember to add tests for your change if possible. Run the unit tests by:
55 |
56 | ```sh
57 | yarn test
58 | ```
59 |
60 | ### Commit message convention
61 |
62 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
63 |
64 | - `fix`: bug fixes, e.g. fix crash due to deprecated method.
65 | - `feat`: new features, e.g. add new method to the module.
66 | - `refactor`: code refactor, e.g. migrate from class components to hooks.
67 | - `docs`: changes into documentation, e.g. add usage example for the module..
68 | - `test`: adding or updating tests, e.g. add integration tests using detox.
69 | - `chore`: tooling changes, e.g. change CI config.
70 |
71 | Our pre-commit hooks verify that your commit message matches this format when committing.
72 |
73 | ### Linting and tests
74 |
75 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/)
76 |
77 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing.
78 |
79 | Our pre-commit hooks verify that the linter and tests pass when committing.
80 |
81 | ### Publishing to npm
82 |
83 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc.
84 |
85 | To publish new versions, run the following:
86 |
87 | ```sh
88 | yarn release
89 | ```
90 |
91 | ### Scripts
92 |
93 | The `package.json` file contains various scripts for common tasks:
94 |
95 | - `yarn bootstrap`: setup project by installing all dependencies and pods.
96 | - `yarn typescript`: type-check files with TypeScript.
97 | - `yarn lint`: lint files with ESLint.
98 | - `yarn test`: run unit tests with Jest.
99 | - `yarn example start`: start the Metro server for the example app.
100 | - `yarn example android`: run the example app on Android.
101 | - `yarn example ios`: run the example app on iOS.
102 |
103 | ### Sending a pull request
104 |
105 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).
106 |
107 | When you're sending a pull request:
108 |
109 | - Prefer small pull requests focused on one change.
110 | - Verify that linters and tests are passing.
111 | - Review the documentation to make sure it looks good.
112 | - Follow the pull request template when opening a pull request.
113 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.
114 |
115 | ## Code of Conduct
116 |
117 | ### Our Pledge
118 |
119 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
120 |
121 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
122 |
123 | ### Our Standards
124 |
125 | Examples of behavior that contributes to a positive environment for our community include:
126 |
127 | - Demonstrating empathy and kindness toward other people
128 | - Being respectful of differing opinions, viewpoints, and experiences
129 | - Giving and gracefully accepting constructive feedback
130 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
131 | - Focusing on what is best not just for us as individuals, but for the overall community
132 |
133 | Examples of unacceptable behavior include:
134 |
135 | - The use of sexualized language or imagery, and sexual attention or
136 | advances of any kind
137 | - Trolling, insulting or derogatory comments, and personal or political attacks
138 | - Public or private harassment
139 | - Publishing others' private information, such as a physical or email
140 | address, without their explicit permission
141 | - Other conduct which could reasonably be considered inappropriate in a
142 | professional setting
143 |
144 | ### Enforcement Responsibilities
145 |
146 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
147 |
148 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
149 |
150 | ### Scope
151 |
152 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
153 |
154 | ### Enforcement
155 |
156 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly.
157 |
158 | All community leaders are obligated to respect the privacy and security of the reporter of any incident.
159 |
160 | ### Enforcement Guidelines
161 |
162 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
163 |
164 | #### 1. Correction
165 |
166 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
167 |
168 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
169 |
170 | #### 2. Warning
171 |
172 | **Community Impact**: A violation through a single incident or series of actions.
173 |
174 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
175 |
176 | #### 3. Temporary Ban
177 |
178 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
179 |
180 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
181 |
182 | #### 4. Permanent Ban
183 |
184 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
185 |
186 | **Consequence**: A permanent ban from any sort of public interaction within the community.
187 |
188 | ### Attribution
189 |
190 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
191 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
192 |
193 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
194 |
195 | [homepage]: https://www.contributor-covenant.org
196 |
197 | For answers to common questions about this code of conduct, see the FAQ at
198 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
199 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 foyarash
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-native-video-controls
2 |
3 | 
4 |
5 | Controls elements and utilities for react-native video players (react-native-video, expo-av, etc.).
6 |
7 | [video-controls-demo.webm](https://user-images.githubusercontent.com/11079152/184147793-7f8785d5-b854-447d-bfbd-30d28ea11207.webm)
8 |
9 |
10 | ## Installation
11 |
12 | ### NPM
13 |
14 | ```sh
15 | npm install @premieroctet/react-native-video-controls
16 | ```
17 |
18 | ### Yarn
19 |
20 | ```sh
21 | yarn add @premieroctet/react-native-video-controls
22 | ```
23 |
24 | Additionally, you need to install [react-native-gesture-handler](https://docs.swmansion.com/react-native-gesture-handler/docs/installation) (at least v2) and [react-native-reanimated](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation) (at least v2).
25 |
26 | No other dependency is required, which makes the lib fully compatible with Expo.
27 |
28 | ## Usage
29 |
30 | A complete example app with a basic usage is available in the [example](example) folder.
31 |
32 | ```tsx
33 |
59 | }
60 | />
61 | ```
62 |
63 | ## API
64 |
65 | See [API](API.md) for the list of available components and hooks.
66 |
67 | ## Contributing
68 |
69 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
70 |
71 | ## License
72 |
73 | MIT
74 |
75 | ## Sponsors
76 |
77 | This project is being developed by [Premier Octet](https://www.premieroctet.com), a Web and mobile agency specializing in React and React Native developments.
78 |
79 | ---
80 |
81 | Inspired from [react-native-video-controls](https://github.com/itsnubix/react-native-video-controls)
82 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: ['module:metro-react-native-babel-preset'],
3 | };
4 |
--------------------------------------------------------------------------------
/example/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-video-controls-example",
3 | "displayName": "VideoControls Example",
4 | "expo": {
5 | "name": "react-native-video-controls-example",
6 | "slug": "react-native-video-controls-example",
7 | "description": "Example app for react-native-video-controls",
8 | "privacy": "public",
9 | "version": "1.0.0",
10 | "platforms": [
11 | "ios",
12 | "android",
13 | "web"
14 | ],
15 | "orientation": "portrait",
16 | "ios": {
17 | "supportsTablet": true
18 | },
19 | "assetBundlePatterns": [
20 | "**/*"
21 | ],
22 | "extra": {
23 | "flipperHack": "React Native packager is running"
24 | },
25 | "android": {
26 | "package": "com.foyarash.reactnativevideocontrolsexample"
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/example/babel.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const pak = require('../package.json');
3 |
4 | module.exports = function (api) {
5 | api.cache(true);
6 |
7 | return {
8 | presets: ['babel-preset-expo'],
9 | plugins: [
10 | [
11 | 'module-resolver',
12 | {
13 | extensions: ['.tsx', '.ts', '.js', '.json'],
14 | alias: {
15 | // For development, we want to alias the library to the source
16 | [pak.name]: path.join(__dirname, '..', pak.source),
17 | 'react-native-reanimated': './node_modules/react-native-reanimated',
18 | 'react-native-gesture-handler':
19 | './node_modules/react-native-gesture-handler',
20 | },
21 | },
22 | ],
23 | 'react-native-reanimated/plugin',
24 | ],
25 | };
26 | };
27 |
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 | import { registerRootComponent } from 'expo';
2 |
3 | import App from './src/App';
4 |
5 | // registerRootComponent calls AppRegistry.registerComponent('main', () => App);
6 | // It also ensures that whether you load the app in the Expo client or in a native build,
7 | // the environment is set up appropriately
8 | registerRootComponent(App);
9 |
--------------------------------------------------------------------------------
/example/metro.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const blacklist = require('metro-config/src/defaults/blacklist');
3 | const escape = require('escape-string-regexp');
4 | const pak = require('../package.json');
5 |
6 | const root = path.resolve(__dirname, '..');
7 |
8 | const modules = Object.keys({
9 | ...pak.peerDependencies,
10 | });
11 |
12 | module.exports = {
13 | projectRoot: __dirname,
14 | watchFolders: [root],
15 |
16 | // We need to make sure that only one version is loaded for peerDependencies
17 | // So we blacklist them at the root, and alias them to the versions in example's node_modules
18 | resolver: {
19 | blacklistRE: blacklist(
20 | modules.map(
21 | (m) =>
22 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
23 | )
24 | ),
25 |
26 | extraNodeModules: modules.reduce((acc, name) => {
27 | acc[name] = path.join(__dirname, 'node_modules', name);
28 | return acc;
29 | }, {}),
30 | },
31 |
32 | transformer: {
33 | getTransformOptions: async () => ({
34 | transform: {
35 | experimentalImportSupport: false,
36 | inlineRequires: true,
37 | },
38 | }),
39 | },
40 | };
41 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-video-controls-example",
3 | "description": "Example app for react-native-video-controls",
4 | "version": "0.0.1",
5 | "private": true,
6 | "main": "index.js",
7 | "scripts": {
8 | "android": "expo start --android",
9 | "ios": "expo start --ios",
10 | "web": "expo start --web",
11 | "start": "expo start",
12 | "test": "jest"
13 | },
14 | "dependencies": {
15 | "expo": "^51.0.0",
16 | "expo-application": "~5.9.1",
17 | "expo-av": "~14.0.5",
18 | "expo-screen-orientation": "~7.0.5",
19 | "expo-splash-screen": "~0.27.5",
20 | "react": "18.2.0",
21 | "react-dom": "18.2.0",
22 | "react-native": "0.74.2",
23 | "react-native-gesture-handler": "~2.16.1",
24 | "react-native-reanimated": "~3.10.1",
25 | "react-native-web": "~0.19.10"
26 | },
27 | "devDependencies": {
28 | "@babel/core": "^7.24.0",
29 | "@babel/runtime": "^7.9.6",
30 | "babel-plugin-module-resolver": "^4.1.0",
31 | "babel-preset-expo": "~11.0.0"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/example/src/App.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import 'react-native-gesture-handler';
3 |
4 | import { FontAwesome } from '@expo/vector-icons';
5 | import {
6 | ComponentProps,
7 | Components,
8 | ControlFullScreen,
9 | ControlFullScreenComponents,
10 | ControlSlider,
11 | ControlSliderMethods,
12 | ControlVideoStateComponents,
13 | VideoControls,
14 | } from '@premieroctet/react-native-video-controls';
15 | import { AVPlaybackStatus, Video } from 'expo-av';
16 | import * as ScreenOrientation from 'expo-screen-orientation';
17 | import { SafeAreaView, StyleSheet, View } from 'react-native';
18 | import { GestureHandlerRootView } from 'react-native-gesture-handler';
19 |
20 | export default function App() {
21 | const controlSliderRef = React.useRef(null);
22 | const videoRef = React.useRef