-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
W.I.P. feat(ios): add PiP functionality #15168
base: master
Are you sure you want to change the base?
Changes from all commits
3561849
2543e9e
15db4a2
8fa68b1
93d884e
a3c3b34
a6105a1
84b0359
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ | |
"react-native-url-polyfill": "2.0.0", | ||
"react-native-video": "6.0.0-alpha.11", | ||
"react-native-watch-connectivity": "1.1.0", | ||
"react-native-webrtc": "124.0.4", | ||
"react-native-webrtc": "git+https://[email protected]/react-native-webrtc/react-native-webrtc.git#6953b21a33382478c9d56674e4d4bd35a30149f9", | ||
"react-native-webview": "13.8.7", | ||
"react-native-youtube-iframe": "2.3.0", | ||
"react-redux": "7.2.9", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import React, { Component } from 'react'; | ||
import { GestureResponderEvent } from 'react-native'; | ||
import { MediaStream, RTCView } from 'react-native-webrtc'; | ||
import React, { useEffect, useRef } from 'react'; | ||
import { GestureResponderEvent, ViewStyle } from 'react-native'; | ||
import { MediaStream, RTCPIPView, startIOSPIP, stopIOSPIP } from 'react-native-webrtc'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { IReduxState } from '../../../../app/types'; | ||
import Pressable from '../../../react/components/native/Pressable'; | ||
import logger from '../../logger'; | ||
|
||
import VideoTransform from './VideoTransform'; | ||
import styles from './styles'; | ||
|
@@ -11,6 +14,12 @@ | |
* The type of the React {@code Component} props of {@link Video}. | ||
*/ | ||
interface IProps { | ||
|
||
/** | ||
* IOS component for PiP view. | ||
*/ | ||
fallbackView: React.Component; | ||
|
||
mirror: boolean; | ||
|
||
onPlaying: Function; | ||
|
@@ -53,82 +62,79 @@ | |
zoomEnabled: boolean; | ||
} | ||
|
||
/** | ||
Check failure on line 65 in react/features/base/media/components/native/Video.tsx GitHub Actions / Lint
|
||
* The React Native {@link Component} which is similar to Web's | ||
* {@code HTMLVideoElement} and wraps around react-native-webrtc's | ||
* {@link RTCView}. | ||
* {@link RTCPIPView}. | ||
*/ | ||
export default class Video extends Component<IProps> { | ||
/** | ||
* React Component method that executes once component is mounted. | ||
* | ||
* @inheritdoc | ||
*/ | ||
componentDidMount() { | ||
const Video: React.FC<IProps> = ({ fallbackView, mirror, onPlaying, onPress, stream, zoomEnabled, zOrder }: IProps) => { | ||
const { enableIosPIP } = useSelector((state: IReduxState) => state['features/mobile/picture-in-picture']); | ||
|
||
const iosPIPOptions = { | ||
fallbackView, | ||
preferredSize: { | ||
width: 400, | ||
height: 800 | ||
}, | ||
startAutomatically: true | ||
}; | ||
const objectFit = zoomEnabled ? 'contain' : 'cover'; | ||
const viewRef = useRef(); | ||
|
||
const rtcView = ( | ||
<RTCPIPView | ||
iosPIP = { iosPIPOptions } | ||
mirror = { mirror } | ||
objectFit = { objectFit } | ||
ref = { viewRef } | ||
streamURL = { stream?.toURL() } | ||
style = { styles.video as ViewStyle } | ||
zOrder = { zOrder } /> | ||
); | ||
|
||
useEffect(() => { | ||
// RTCView currently does not support media events, so just fire | ||
// onPlaying callback when <RTCView> is rendered. | ||
const { onPlaying } = this.props; | ||
|
||
onPlaying?.(); | ||
} | ||
}, []); | ||
|
||
/** | ||
* Implements React's {@link Component#render()}. | ||
* | ||
* @inheritdoc | ||
* @returns {ReactElement|null} | ||
*/ | ||
render() { | ||
const { onPress, stream, zoomEnabled } = this.props; | ||
|
||
if (stream) { | ||
// RTCView | ||
const style = styles.video; | ||
const objectFit | ||
= zoomEnabled | ||
? 'contain' | ||
: 'cover'; | ||
const rtcView | ||
= ( | ||
<RTCView | ||
mirror = { this.props.mirror } | ||
objectFit = { objectFit } | ||
streamURL = { stream.toURL() } | ||
style = { style } | ||
zOrder = { this.props.zOrder } /> | ||
); | ||
|
||
// VideoTransform implements "pinch to zoom". As part of "pinch to | ||
// zoom", it implements onPress, of course. | ||
if (zoomEnabled) { | ||
return ( | ||
<VideoTransform | ||
enabled = { zoomEnabled } | ||
onPress = { onPress } | ||
streamId = { stream.id } | ||
style = { style }> | ||
{ rtcView } | ||
</VideoTransform> | ||
); | ||
} | ||
|
||
// XXX Unfortunately, VideoTransform implements a custom press | ||
// detection which has been observed to be very picky about the | ||
// precision of the press unlike the builtin/default/standard press | ||
// detection which is forgiving to imperceptible movements while | ||
// pressing. It's not acceptable to be so picky, especially when | ||
// "pinch to zoom" is not enabled. | ||
return ( | ||
<Pressable onPress = { onPress }> | ||
{ rtcView } | ||
</Pressable> | ||
); | ||
useEffect(() => { | ||
if (enableIosPIP) { | ||
logger.warn('Picture in picture mode on'); | ||
startIOSPIP(viewRef); | ||
} else { | ||
logger.warn('Picture in picture mode off'); | ||
stopIOSPIP(viewRef); | ||
} | ||
}, [ enableIosPIP ]); | ||
|
||
// RTCView has peculiarities which may or may not be platform specific. | ||
// For example, it doesn't accept an empty streamURL. If the execution | ||
// reached here, it means that we explicitly chose to not initialize an | ||
// RTCView as a way of dealing with its idiosyncrasies. | ||
return null; | ||
// VideoTransform implements "pinch to zoom". As part of "pinch to | ||
// zoom", it implements onPress, of course. | ||
if (zoomEnabled) { | ||
return ( | ||
<VideoTransform | ||
enabled = { zoomEnabled } | ||
onPress = { onPress } | ||
streamId = { stream?.id } | ||
style = { styles.video as ViewStyle }> | ||
{ rtcView } | ||
</VideoTransform> | ||
); | ||
} | ||
} | ||
|
||
// XXX Unfortunately, VideoTransform implements a custom press | ||
// detection which has been observed to be very picky about the | ||
// precision of the press unlike the builtin/default/standard press | ||
// detection which is forgiving to imperceptible movements while | ||
// pressing. It's not acceptable to be so picky, especially when | ||
// "pinch to zoom" is not enabled. | ||
return ( | ||
<Pressable onPress = { onPress }> | ||
{ rtcView } | ||
</Pressable> | ||
); | ||
|
||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ISSUE: @typescript-eslint/ban-ts-comment (Severity: Medium) Remediation: 🤖 powered by PullRequest Automation 👋 verified by Xiaoyong W |
||
// @ts-ignore | ||
export default Video; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ISSUE: @typescript-eslint/ban-types (Severity: Medium)
Don't use
Function
as a type. TheFunction
type accepts any function-like value.It provides no type safety when calling the function, which can be a common source of bugs.
It also accepts things like class declarations, which will throw at runtime as they will not be called with
new
.If you are expecting the function to accept certain arguments, you should explicitly define the function shape.
Remediation:
I understand this is not part of the change but this is a good best practice recommendation from the automation. Please consider improving in the future
🤖 powered by PullRequest Automation 👋 verified by Xiaoyong W