Skip to content

Conversation

@saseungmin
Copy link
Member

@saseungmin saseungmin commented Jul 15, 2025

  • Migration Guide: v1 to v2
  • v1 Legacy Version
  • update v1 to v2 guide

Summary by CodeRabbit

  • New Features

    • Introduced a new hooks-based API with useYouTubePlayer and useYouTubeEvent for easier player management and event handling.
    • Added the YoutubeView component for rendering YouTube players using the new API.
    • Improved support for multiple player instances and enhanced memory management.
  • Bug Fixes

    • Resolved memory leaks through automatic cleanup in the new hooks.
  • Documentation

    • Updated and expanded documentation in both English and Korean to reflect the new API, including a detailed migration guide from v1 to v2.
    • Added legacy documentation for v1 and clarified usage examples and migration steps.
  • Breaking Changes

    • Removed the YoutubePlayer component and ref-based API; all event props and ref controls are replaced by the new hooks-based approach.
    • Event handling and player controls now require the new hooks and player instance pattern.

- Migration Guide: v1 to v2
- v1 Legacy Version
- update v1 to v2 guide
@changeset-bot
Copy link

changeset-bot bot commented Jul 15, 2025

⚠️ No Changeset found

Latest commit: 4e771d0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 4 packages
Name Type
react-native-youtube-bridge Major
@react-native-youtube-bridge/react Major
@react-native-youtube-bridge/core Major
@react-native-youtube-bridge/web Major

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Jul 15, 2025

Walkthrough

This update marks a major, breaking release (v2.0) of the React Native YouTube Bridge library, transitioning from a ref-based, imperative API to a fully declarative, hooks-based architecture. The YoutubePlayer component and its ref interface are replaced by YoutubeView and two new hooks: useYouTubePlayer for player instantiation/configuration and useYouTubeEvent for event handling. All documentation is updated, and a migration guide is added.

Changes

Files / Paths Change Summary
.changeset/funny-moons-hear.md, .changeset/tired-papayas-sleep.md Added and removed changesets documenting the major v2 API redesign and a previously added Store class.
README.md, README-ko_kr.md, packages/react-native-youtube-bridge/README.md, .../README-ko_kr.md Updated documentation to reflect the new hooks-based API (useYouTubePlayer, useYouTubeEvent, YoutubeView), removed references to YoutubePlayer and ref usage, added migration instructions, revised all examples and event handling patterns, and clarified rendering modes.
packages/react-native-youtube-bridge/docs/migration-v2.md Added a migration guide for upgrading from v1 to v2, including side-by-side code examples, required migration steps, and a summary of breaking changes.
packages/react-native-youtube-bridge/docs/v1.md Added legacy documentation for v1, covering the old YoutubePlayer component, ref-based API, event handling, and usage patterns.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant useYouTubePlayer
    participant YoutubeView
    participant useYouTubeEvent

    App->>useYouTubePlayer: Create player instance (videoId, config)
    useYouTubePlayer-->>App: Return player object
    App->>YoutubeView: Render <YoutubeView player={player} />
    App->>useYouTubeEvent: Subscribe to events (player, eventName, ...)
    useYouTubeEvent-->>App: Provide event data (callback or state)
    App->>player: Call control methods (play, pause, seekTo, stop)
Loading

Possibly related PRs

Poem

🐇
Goodbye to refs and props of old,
Hooks and views, a new story told!
YoutubeView and hooks in hand,
Events and playback at your command.
Docs refreshed, migration clear—
v2 is here, let’s hop and cheer!


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cloudflare-workers-and-pages
Copy link

Deploying react-native-youtube-bridge-example with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4e771d0
Status: ✅  Deploy successful!
Preview URL: https://0d4d929f.react-native-youtube-bridge-example.pages.dev
Branch Preview URL: https://docs-update-v2.react-native-youtube-bridge-example.pages.dev

View logs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (13)
packages/react-native-youtube-bridge/docs/v1.md (2)

24-26: Add alt text to the demo GIF image

The <img> tag lacks an alt attribute, triggering MD045 and reducing accessibility/compliance.

-  <img src="https://raw.githubusercontent.com/react-native-bridges/react-native-youtube-bridge/main/assets/example.gif" width="600" />
+  <img src="https://raw.githubusercontent.com/react-native-bridges/react-native-youtube-bridge/main/assets/example.gif"
+       width="600"
+       alt="Demo of react-native-youtube-bridge v1 in action" />

267-270: Use a proper heading instead of bold text

The bold line **Custom Player Page** is flagged by MD036. Convert it to a heading for consistency with the rest of the document.

-**Custom Player Page**
+#### Custom Player Page
packages/react-native-youtube-bridge/docs/migration-v2.md (1)

125-126: Remove punctuation from the heading

#### \useYouTubeEvent` Usage Patterns:` ends with a colon, causing MD026. Dropping the colon keeps the heading clean.

-#### `useYouTubeEvent` Usage Patterns:
+#### `useYouTubeEvent` Usage Patterns
README.md (2)

31-33: Provide alt text for the example GIF

Same accessibility issue as in the v1 docs.

-  <img src="./assets/example.gif" width="600" />
+  <img src="./assets/example.gif" width="600" alt="Demo of react-native-youtube-bridge" />

74-80: progressInterval is used but never defined

In the sample code progressInterval is referenced (lines 78-79) without being declared, which will throw a reference error if copied verbatim.

Add a local constant or inline a numeric literal.

-  const progress = useYouTubeEvent(player, 'progress', progressInterval);
+  const progressInterval = 1000; // ms
+  const progress = useYouTubeEvent(player, 'progress', progressInterval);
packages/react-native-youtube-bridge/README-ko_kr.md (2)

30-32: 이미지에 대체 텍스트(alt) 추가

접근성과 MD045 준수를 위해 alt 속성을 추가해주세요.

-  <img src="https://raw.githubusercontent.com/react-native-bridges/react-native-youtube-bridge/main/assets/example.gif" width="600" />
+  <img src="https://raw.githubusercontent.com/react-native-bridges/react-native-youtube-bridge/main/assets/example.gif"
+       width="600"
+       alt="react-native-youtube-bridge 데모" />

74-78: progressInterval 정의 누락

예제 코드에 progressInterval 변수가 선언되지 않아 그대로 복사 시 오류가 발생합니다.

-  const progress = useYouTubeEvent(player, 'progress', progressInterval);
+  const progressInterval = 1000; // ms
+  const progress = useYouTubeEvent(player, 'progress', progressInterval);
packages/react-native-youtube-bridge/README.md (3)

5-7: Use GitHub-compatible callouts

[!note] blocks render only on Microsoft Docs–style engines and are ignored on GitHub; the notice will silently disappear. Replace with a standard blockquote so the warning is visible to all readers.

-> [!note]
-> **V1 users:** [V1 Documentation](/packages/react-native-youtube-bridge/docs/v1.md) | [V2 Migration Guide](/packages/react-native-youtube-bridge/docs/migration-v2.md)
+> **Note for V1 users:**  
+> [V1 Documentation](/packages/react-native-youtube-bridge/docs/v1.md) · [V2 Migration Guide](/packages/react-native-youtube-bridge/docs/migration-v2.md)

18-23: Capitalize “WebView” for consistency

Everywhere else the README uses the React-Native component name “WebView”. Keeping the same casing avoids cognitive friction.

- ✅ Flexible rendering modes (inline HTML & webview)
+ ✅ Flexible rendering modes (inline HTML & WebView)

50-61: Add missing imports in the quick-start snippet

The example won’t compile when pasted into a fresh file because React is not in scope. A one-liner keeps the snippet self-contained.

-import { YoutubeView, useYouTubePlayer } from 'react-native-youtube-bridge';
+import React from 'react';
+import { YoutubeView, useYouTubePlayer } from 'react-native-youtube-bridge';
README-ko_kr.md (3)

5-7: [!note] 블록은 GitHub에서 렌더링되지 않습니다

GitHub Markdown은 [!note] 구문을 지원하지 않습니다. 일반 인용문 형식으로 변경해 주세요.

-> [!note]
-> **V1 사용자:** [V1 문서](/packages/react-native-youtube-bridge/docs/v1.md) | [V2 마이그레이션 가이드](/packages/react-native-youtube-bridge/docs/migration-v2.md)
+> **참고 – V1 사용자용 문서:**  
+> [V1 문서](/packages/react-native-youtube-bridge/docs/v1.md) · [V2 마이그레이션 가이드](/packages/react-native-youtube-bridge/docs/migration-v2.md)

18-23: “WebView” 표기로 통일 권장

불릿 목록에서만 소문자 webview를 사용하고 이후엔 “WebView”를 사용합니다. 일관성을 유지하면 가독성이 좋아집니다.


50-61: 예제 코드에 React import 누락

초심자도 바로 실행할 수 있도록 React import 를 추가해 주세요.

-import { YoutubeView, useYouTubePlayer } from 'react-native-youtube-bridge';
+import React from 'react';
+import { YoutubeView, useYouTubePlayer } from 'react-native-youtube-bridge';
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae4cc4d and 4e771d0.

📒 Files selected for processing (8)
  • .changeset/funny-moons-hear.md (1 hunks)
  • .changeset/tired-papayas-sleep.md (0 hunks)
  • README-ko_kr.md (8 hunks)
  • README.md (6 hunks)
  • packages/react-native-youtube-bridge/README-ko_kr.md (7 hunks)
  • packages/react-native-youtube-bridge/README.md (6 hunks)
  • packages/react-native-youtube-bridge/docs/migration-v2.md (1 hunks)
  • packages/react-native-youtube-bridge/docs/v1.md (1 hunks)
💤 Files with no reviewable changes (1)
  • .changeset/tired-papayas-sleep.md
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
packages/react-native-youtube-bridge/docs/v1.md

25-25: Images should have alternate text (alt text)

(MD045, no-alt-text)


241-241: Bare URL used

(MD034, no-bare-urls)


267-267: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

packages/react-native-youtube-bridge/docs/migration-v2.md

125-125: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)

packages/react-native-youtube-bridge/README.md

247-247: Bare URL used

(MD034, no-bare-urls)


273-273: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

README-ko_kr.md

240-240: Bare URL used

(MD034, no-bare-urls)

🔇 Additional comments (1)
.changeset/funny-moons-hear.md (1)

100-104: Links rely on repo-relative paths – verify they resolve in the changelog on npm

[Migration Guide](/packages/react-native-youtube-bridge/docs/migration-v2.md) may break when the file is rendered on the npm package page (the root differs). Consider replacing with an absolute GitHub URL or a docs website link.

Comment on lines +67 to 98
[Events](https://developers.google.com/youtube/iframe_api_reference#Events) are fired to communicate YouTube iframe API state changes to your application.

```tsx
function App() {
const playerRef = useRef<PlayerControls>(null);
The `useYouTubeEvent` hook provides complete type inference and allows you to easily detect and use events in two ways.

const handleReady = useCallback(() => {
console.log('Player is ready!');
}, []);
```tsx
import { YoutubeView, useYouTubeEvent, useYouTubePlayer } from 'react-native-youtube-bridge';

const handleStateChange = useCallback((state: PlayerState) => {
console.log('Player state changed:', state);
}, []);
function App() {
const player = useYouTubePlayer(videoIdOrUrl);

const handlePlaybackRateChange = useCallback((rate: number) => {
console.log('Playback rate changed:', rate);
}, []);
const playbackRate = useYouTubeEvent(player, 'playbackRateChange', 1);
const progress = useYouTubeEvent(player, 'progress', progressInterval);

const handlePlaybackQualityChange = useCallback((quality: string) => {
console.log('Playback quality changed:', quality);
}, []);
useYouTubeEvent(player, 'ready', (playerInfo) => {
console.log('Player is ready!');
Alert.alert('Alert', 'YouTube player is ready!');
});

const handleAutoplayBlocked = useCallback(() => {
useYouTubeEvent(player, 'autoplayBlocked', () => {
console.log('Autoplay was blocked');
}, []);
});

const handleError = useCallback((error: YouTubeError) => {
useYouTubeEvent(player, 'error', (error) => {
console.error('Player error:', error);
}, []);
Alert.alert('Error', `Player error (${error.code}): ${error.message}`);
});

return (
<YoutubePlayer
onReady={handleReady}
onStateChange={handleStateChange}
onError={handleError}
onPlaybackRateChange={handlePlaybackRateChange}
onPlaybackQualityChange={handlePlaybackQualityChange}
onAutoplayBlocked={handleAutoplayBlocked}
/>
)
<YoutubeView player={player} />
);
}
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

progressInterval is undefined

The variable is referenced before declaration, which will throw at runtime if users copy the code verbatim. Declare it (or inline the literal) before passing it to the hook.

   const playbackRate = useYouTubeEvent(player, 'playbackRateChange', 1);
-  const progress = useYouTubeEvent(player, 'progress', progressInterval);
+  const progressInterval = 1000; // ms
+  const progress = useYouTubeEvent(player, 'progress', progressInterval);
🤖 Prompt for AI Agents
In packages/react-native-youtube-bridge/README.md between lines 67 and 98, the
example code uses the variable progressInterval without declaring it first,
which causes a runtime error if copied as is. Fix this by declaring
progressInterval with an appropriate value before using it in the
useYouTubeEvent hook or replace it inline with a numeric literal to ensure it is
defined.

Comment on lines +65 to 96
YouTube iframe API의 상태 변화를 애플리케이션에 전달하기 위해 [이벤트](https://developers.google.com/youtube/iframe_api_reference#Events)를 발생시킵니다.

> 🔔 Note - 성능 최적화 및 비정상 동작 방지를 위해 콜백 함수는 `useCallback`으로 감싸주세요.
`useYouTubeEvent` hook을 사용하여 완벽한 타입 추론을 지원하며, 두 가지 방법으로 이벤트를 쉽게 감지하여 사용할 수 있습니다.

```tsx
function App() {
const playerRef = useRef<PlayerControls>(null);

const handleReady = useCallback(() => {
console.log('플레이어 준비 완료!');
}, []);
import { YoutubeView, useYouTubeEvent, useYouTubePlayer } from 'react-native-youtube-bridge';

const handleStateChange = useCallback((state: PlayerState) => {
console.log('플레이어 상태 변경:', state);
}, []);
function App() {
const player = useYouTubePlayer(videoIdOrUrl);

const handlePlaybackRateChange = useCallback((rate: number) => {
console.log('재생 속도 변경:', rate);
}, []);
const playbackRate = useYouTubeEvent(player, 'playbackRateChange', 1);
const progress = useYouTubeEvent(player, 'progress', progressInterval);

const handlePlaybackQualityChange = useCallback((quality: string) => {
console.log('재생 품질 변경:', quality);
}, []);
useYouTubeEvent(player, 'ready', (playerInfo) => {
console.log('Player is ready!');
Alert.alert('Alert', 'YouTube player is ready!');
});

const handleAutoplayBlocked = useCallback(() => {
console.log('자동 재생이 차단되었습니다');
}, []);
useYouTubeEvent(player, 'autoplayBlocked', () => {
console.log('Autoplay was blocked');
});

const handleError = useCallback((error: YouTubeError) => {
console.error('플레이어 오류:', error);
}, []);
useYouTubeEvent(player, 'error', (error) => {
console.error('Player error:', error);
Alert.alert('Error', `Player error (${error.code}): ${error.message}`);
});

return (
<YoutubePlayer
onReady={handleReady}
onStateChange={handleStateChange}
onError={handleError}
onPlaybackRateChange={handlePlaybackRateChange}
onPlaybackQualityChange={handlePlaybackQualityChange}
onAutoplayBlocked={handleAutoplayBlocked}
/>
)
<YoutubeView player={player} />
);
}
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

progressInterval 변수가 선언되지 않았습니다

예제를 그대로 복사하면 progressInterval이 정의되지 않아 에러가 발생합니다.

   const playbackRate = useYouTubeEvent(player, 'playbackRateChange', 1);
-  const progress = useYouTubeEvent(player, 'progress', progressInterval);
+  const progressInterval = 1000; // ms
+  const progress = useYouTubeEvent(player, 'progress', progressInterval);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
YouTube iframe API의 상태 변화를 애플리케이션에 전달하기 위해 [이벤트](https://developers.google.com/youtube/iframe_api_reference#Events)를 발생시킵니다.
> 🔔 Note - 성능 최적화 및 비정상 동작 방지를 위해 콜백 함수는 `useCallback`으로 감싸주세요.
`useYouTubeEvent` hook을 사용하여 완벽한 타입 추론을 지원하며, 두 가지 방법으로 이벤트를 쉽게 감지하여 사용할 수 있습니다.
```tsx
function App() {
const playerRef = useRef<PlayerControls>(null);
const handleReady = useCallback(() => {
console.log('플레이어 준비 완료!');
}, []);
import { YoutubeView, useYouTubeEvent, useYouTubePlayer } from 'react-native-youtube-bridge';
const handleStateChange = useCallback((state: PlayerState) => {
console.log('플레이어 상태 변경:', state);
}, []);
function App() {
const player = useYouTubePlayer(videoIdOrUrl);
const handlePlaybackRateChange = useCallback((rate: number) => {
console.log('재생 속도 변경:', rate);
}, []);
const playbackRate = useYouTubeEvent(player, 'playbackRateChange', 1);
const progress = useYouTubeEvent(player, 'progress', progressInterval);
const handlePlaybackQualityChange = useCallback((quality: string) => {
console.log('재생 품질 변경:', quality);
}, []);
useYouTubeEvent(player, 'ready', (playerInfo) => {
console.log('Player is ready!');
Alert.alert('Alert', 'YouTube player is ready!');
});
const handleAutoplayBlocked = useCallback(() => {
console.log('자동 재생이 차단되었습니다');
}, []);
useYouTubeEvent(player, 'autoplayBlocked', () => {
console.log('Autoplay was blocked');
});
const handleError = useCallback((error: YouTubeError) => {
console.error('플레이어 오류:', error);
}, []);
useYouTubeEvent(player, 'error', (error) => {
console.error('Player error:', error);
Alert.alert('Error', `Player error (${error.code}): ${error.message}`);
});
return (
<YoutubePlayer
onReady={handleReady}
onStateChange={handleStateChange}
onError={handleError}
onPlaybackRateChange={handlePlaybackRateChange}
onPlaybackQualityChange={handlePlaybackQualityChange}
onAutoplayBlocked={handleAutoplayBlocked}
/>
)
<YoutubeView player={player} />
);
}
```
const playbackRate = useYouTubeEvent(player, 'playbackRateChange', 1);
const progressInterval = 1000; // ms
const progress = useYouTubeEvent(player, 'progress', progressInterval);
🤖 Prompt for AI Agents
In README-ko_kr.md between lines 65 and 96, the example code uses the variable
progressInterval without declaring it, causing an error. To fix this, declare
and initialize progressInterval with an appropriate numeric value before using
it in the useYouTubeEvent hook for the 'progress' event. This ensures the
example runs without errors and clearly shows how to use the interval parameter.

@saseungmin saseungmin merged commit 0fdeec7 into main Jul 15, 2025
5 checks passed
@saseungmin saseungmin deleted the docs/update-v2 branch July 15, 2025 07:55
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

Successfully merging this pull request may close these issues.

2 participants