首页 > 解决方案 > 如何使用“react-native-android-pip”?

问题描述

我该如何使用它:https ://www.npmjs.com/package/react-native-android-pip 我想做一个 webview 应用程序可以使用 PIP(画中画)。但是我怎么能在我的代码中使用这个模块。

import * as React from 'react';
import { WebView } from 'react-native-webview';
import AndroidPip from 'react-native-android-pip';

export default class App extends React.Component {
  render() {
    return <WebView source={{ uri: '(My url)' }} style={{ marginTop: 50 }} />;
  }
}

标签: react-native

解决方案


正如这里所说(关于文档本身),您可以使用如下:

import AndroidPip from 'react-native-android-pip';


// Enter Pip mode
AndroidPip.enterPictureInPictureMode() 

//Configure aspect ratio, works only on SDK version 26 and above
AndroidPip.configureAspectRatio(width, height) 


// When enabled, PIP mode will be automatically entered when app is unfocused( User presses home
//, menu button etc)
AndroidPip.enableAutoPipSwitch()
AndroidPip.disableAutoPipSwitch()

您可以通过单击按钮、响应 API、启动屏幕等来调用这些函数...

[编辑] 另外,尝试使用这个模块的 github 版本,因为 npm 版本是 2 岁,而 github 版本是 29 天没有更新。安装如下:

npm install --save https://github.com/shaun-chiang/rn-android-pip


推荐阅读