Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 88e816c

Browse files
Yupeng-liYupeng Li
and
Yupeng Li
authored
fix: Open YouTube video on a browser or YouTube app (iOS only) (#300)
* fix: Open YouTube video on a browser or YouTube app when tapping on the title or the YouTube logo on the player * Use console.warn instead of console.error when a youtube link cannot be opened. #codereviewchanges --------- Co-authored-by: Yupeng Li <yupeng.li@livingwith.health>
1 parent 2a3234c commit 88e816c

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

‎src/YoutubeIframe.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React, {
77
useCallback,
88
useImperativeHandle,
99
} from 'react';
10-
import {Platform, StyleSheet, View} from 'react-native';
10+
import {Linking,Platform, StyleSheet, View} from 'react-native';
1111
import {EventEmitter} from 'events';
1212
import {WebView} from './WebView';
1313
import {
@@ -211,10 +211,20 @@ const YoutubeIframe = (props, ref) => {
211211
request => {
212212
try {
213213
const url = request.mainDocumentURL || request.url;
214-
const iosFirstLoad = Platform.OS === 'ios' && url === 'about:blank';
215-
const shouldLoad =
216-
iosFirstLoad || url.startsWith(baseUrlOverride || DEFAULT_BASE_URL);
217-
return shouldLoad;
214+
if (Platform.OS === 'ios') {
215+
const iosFirstLoad = url === 'about:blank';
216+
if (iosFirstLoad) {
217+
return true;
218+
}
219+
const isYouTubeLink = url.startsWith('https://www.youtube.com/');
220+
if (isYouTubeLink) {
221+
Linking.openURL(url).catch(error => {
222+
console.warn('Error opening URL:', error);
223+
});
224+
return false;
225+
}
226+
}
227+
return url.startsWith(baseUrlOverride || DEFAULT_BASE_URL);
218228
} catch (error) {
219229
// defaults to true in case of error
220230
// returning false stops the video from loading

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /