MattWeiler / expo-pip

A library that provides access to Picture In Picture API for Android only.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

expo-pip

A library that provides access to Picture In Picture API for Android only.

expo-pip is not available in Expo Go, learn more about development builds.

API documentation

Installation in managed Expo projects

For managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release. If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release.

Installation in bare React Native projects

For bare React Native projects, you must ensure that you have installed and configured the expo package before continuing.

Add the package to your npm dependencies

npx expo install expo-pip

Demo

Usage

import * as ExpoPip from "expo-pip";
import { useState } from "react";
import { Button, StyleSheet, Text, View } from "react-native";

export default function App() {
  const { isInPipMode } = ExpoPip.useIsInPip();
  const [automaticEnterEnabled, setAutomaticEnterEnabled] = useState(false);

  return (
    <View style={styles.container}>
      <Text>{isInPipMode ? "In Pip Mode 😎" : "Not In Pip Mode"}</Text>
      {!isInPipMode && (
        <>
          <Button
            onPress={() =>
              ExpoPip.enterPipMode({
                width: 200,
                height: 300,
              })
            }
            title="Go to Picture In Picture Mode"
          />
          <Button
            onPress={() => {
              const newValue = !automaticEnterEnabled;
              setAutomaticEnterEnabled(newValue);
              ExpoPip.setAutoEnterEnabled(newValue);
            }}
            title={`Toggle automaticEnter: ${automaticEnterEnabled ? "on" : "off"}`}
          />
        </>
      )}
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});

API

import * as ExpoPip from "expo-pip";

Receive updates about Picture In Picture Mode status

const { isInPipMode } = ExpoPip.useIsInPip();

Enter and exit auto enter mode

ExpoPip.setAutoEnterEnabled(true);

Set desired aspect ratio

ExpoPip.setAspectRatio({ width: 200, height: 300 });

Enter Picture In Picture mode with desired size

ExpoPip.enterPipMode({ width: 200, height: 300 });

Params are opcional. Defaults values are 200 width and 300 height.

Contributing

Contributions are very welcome! Please refer to guidelines described in the contributing guide.

About

A library that provides access to Picture In Picture API for Android only.


Languages

Language:Kotlin 34.8%Language:TypeScript 20.2%Language:Ruby 17.5%Language:Objective-C++ 14.8%Language:JavaScript 9.8%Language:Objective-C 1.8%Language:Swift 0.6%Language:C 0.6%