Skip to content

Commit

Permalink
✨ feat: add setAspectRatio
Browse files Browse the repository at this point in the history
  • Loading branch information
EdgarJMesquita committed Apr 17, 2024
1 parent 088e936 commit f61a1e5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ const { isInPipMode } = ExpoPip.useIsInPip();
ExpoPip.setAutoEnterEnabled(true);
```

### Set desired aspect ratio

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

### Enter Picture In Picture mode with desired size

```js
Expand Down
12 changes: 10 additions & 2 deletions android/src/main/java/expo/modules/pip/ExpoPipModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ class ExpoPipModule : Module() {
}
}

Function("setAspectRatio"){ width:Int, height:Int ->
val pictureInPictureParamsBuilder = PictureInPictureParams.Builder()
val ratio = Rational(width, height)
pictureInPictureParamsBuilder.setAspectRatio(ratio)
appContext.currentActivity?.setPictureInPictureParams(pictureInPictureParamsBuilder.build())

}

Function("enterPipMode") { width:Int?, height:Int? ->
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
val ratWidth = width ?: 200
Expand All @@ -36,10 +44,10 @@ class ExpoPipModule : Module() {

val pictureInPictureParamsBuilder = PictureInPictureParams.Builder()

pictureInPictureParamsBuilder.setAspectRatio(ratio).build()
pictureInPictureParamsBuilder.setAspectRatio(ratio)

appContext.currentActivity?.enterPictureInPictureMode(pictureInPictureParamsBuilder.build())
}
}
}
}
}
2 changes: 1 addition & 1 deletion example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function App() {
<Button
onPress={() =>
ExpoPip.enterPipMode({
width: 300,
width: 200,
height: 300,
})
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expo-pip",
"version": "0.1.0",
"version": "0.2.0",
"description": "A library that provides access to Picture In Picture API for Android only",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/ExpoPip.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type EnterPipModeProps = {
export type AspectRatioProps = {
width: number;
height: number;
};
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import ExpoPipModule from "./ExpoPipModule";
import { useEffect, useState } from "react";
import { AppState } from "react-native";
import { EnterPipModeProps } from "./ExpoPip.types";

import { AspectRatioProps } from "./ExpoPip.types";
import ExpoPipModule from "./ExpoPipModule";

export function isInPipMode(): boolean {
return ExpoPipModule.isInPipMode();
}

export function enterPipMode(props?: EnterPipModeProps) {
export function enterPipMode(props?: AspectRatioProps) {
const defaultParams = {
width: 200,
height: 300,
Expand All @@ -18,6 +19,10 @@ export function enterPipMode(props?: EnterPipModeProps) {
ExpoPipModule.enterPipMode(props.width, props.height);
}

export function setAspectRatio({ width, height }: AspectRatioProps) {
ExpoPipModule.setAspectRatio(width, height);
}

export function setAutoEnterEnabled(isAutomatic: boolean) {
ExpoPipModule.setAutoEnterEnabled(isAutomatic);
}
Expand Down

0 comments on commit f61a1e5

Please sign in to comment.