Skip to content

Commit 7363fd5

Browse files
authored
Add use fullscreen intent (#944)
1 parent 685da2a commit 7363fd5

File tree

17 files changed

+84
-4
lines changed

17 files changed

+84
-4
lines changed

README.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -811,16 +811,17 @@ requestMultiple([PERMISSIONS.IOS.CAMERA, PERMISSIONS.IOS.FACE_ID]).then((statuse
811811

812812
#### openSettings
813813

814-
Open application / alarms / notifications settings (default to `application`).
814+
Open application / alarms / notifications / fullscreen settings (default to `application`).
815815

816816
> [!NOTE]
817817
>
818818
> - `notifications` settings are only available on Android 8+ and iOS 15.4+
819819
> - `alarms` settings are only available on Android 12+
820+
> - `fullscreen` settings are only available on Android 14+
820821
> - If a choice is not available, it fallbacks to `application` settings
821822
822823
```ts
823-
function openSettings(type?: 'application' | 'alarms' | 'notifications'): Promise<void>;
824+
function openSettings(type?: 'application' | 'alarms' | 'notifications' | 'fullscreen'): Promise<void>;
824825
```
825826

826827
```ts
@@ -845,6 +846,23 @@ canScheduleExactAlarms()
845846
.catch(() => console.warn('Cannot check exact alarms scheduling setting'));
846847
```
847848

849+
850+
#### canUseFullScreenIntent (Android)
851+
852+
Check if your app can use full screen intent.
853+
854+
```ts
855+
function canUseFullScreenIntent(): Promise<boolean>;
856+
```
857+
858+
```ts
859+
import {canUseFullScreenIntent} from 'react-native-permissions';
860+
861+
canUseFullScreenIntent()
862+
.then((value) => console.log(`Can use full screen intent: ${value}`))
863+
.catch(() => console.warn('Cannot check full screen intent using setting'));
864+
```
865+
848866
#### openPhotoPicker (iOS 14+)
849867

850868
Open a picker to update the photo selection when `PhotoLibrary` permission is `limited`. This will reject if unsupported or if full permission is already `granted`.

android/src/main/java/com/zoontek/rnpermissions/RNPermissionsModuleImpl.kt

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.zoontek.rnpermissions
22

33
import android.app.AlarmManager
4+
import android.app.NotificationManager
45
import android.content.Context
56
import android.content.Intent
67
import android.content.pm.PackageManager
@@ -70,6 +71,10 @@ object RNPermissionsModuleImpl {
7071
setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
7172
putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
7273
}
74+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && type == "fullscreen" -> Intent().apply {
75+
setAction(Settings.ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT)
76+
setData(Uri.parse("package:${packageName}"))
77+
}
7378
else -> Intent().apply {
7479
setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
7580
setData(Uri.parse("package:${packageName}"))
@@ -96,6 +101,17 @@ object RNPermissionsModuleImpl {
96101
promise.resolve(canScheduleExactAlarms)
97102
}
98103

104+
fun canUseFullScreenIntent(reactContext: ReactApplicationContext, promise: Promise) {
105+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
106+
return promise.resolve(true)
107+
}
108+
109+
val notificationManager = reactContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
110+
val canUseFullScreenIntent = notificationManager.canUseFullScreenIntent()
111+
112+
promise.resolve(canUseFullScreenIntent)
113+
}
114+
99115
fun check(reactContext: ReactApplicationContext, permission: String, promise: Promise) {
100116
if (!isPermissionAvailable(permission)) {
101117
return promise.resolve(UNAVAILABLE)

android/src/newarch/com/zoontek/rnpermissions/RNPermissionsModule.kt

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class RNPermissionsModule(reactContext: ReactApplicationContext?) :
2727
RNPermissionsModuleImpl.canScheduleExactAlarms(reactApplicationContext, promise)
2828
}
2929

30+
override fun canUseFullScreenIntent(promise: Promise) {
31+
RNPermissionsModuleImpl.canUseFullScreenIntent(reactApplicationContext, promise)
32+
}
33+
3034
override fun check(permission: String, promise: Promise) {
3135
RNPermissionsModuleImpl.check(reactApplicationContext, permission, promise)
3236
}

android/src/oldarch/com/zoontek/rnpermissions/RNPermissionsModule.kt

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class RNPermissionsModule(reactContext: ReactApplicationContext?) :
3131
RNPermissionsModuleImpl.canScheduleExactAlarms(reactApplicationContext, promise)
3232
}
3333

34+
@ReactMethod
35+
fun canUseFullScreenIntent(promise: Promise) {
36+
RNPermissionsModuleImpl.canUseFullScreenIntent(reactApplicationContext, promise)
37+
}
38+
3439
@ReactMethod
3540
fun check(permission: String, promise: Promise) {
3641
RNPermissionsModuleImpl.check(reactApplicationContext, permission, promise)

ios/RNPermissions.mm

+5
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ - (void)canScheduleExactAlarms:(RCTPromiseResolveBlock)resolve
460460
reject(@"RNPermissions:canScheduleExactAlarms", @"canScheduleExactAlarms is not supported on iOS", nil);
461461
}
462462

463+
- (void)canUseFullScreenIntent:(RCTPromiseResolveBlock)resolve
464+
reject:(RCTPromiseRejectBlock)reject {
465+
reject(@"RNPermissions:canUseFullScreenIntent", @"canUseFullScreenIntent is not supported on iOS", nil);
466+
}
467+
463468
- (void)shouldShowRequestRationale:(NSString *)permission
464469
resolve:(RCTPromiseResolveBlock)resolve
465470
reject:(RCTPromiseRejectBlock)reject {

mock.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const PERMISSIONS = {ANDROID, IOS, WINDOWS};
1313
export {PERMISSIONS, RESULTS};
1414

1515
export const canScheduleExactAlarms = jest.fn(async () => true);
16+
export const canUseFullScreenIntent = jest.fn(async () => true);
1617
export const check = jest.fn(async () => RESULTS.GRANTED);
1718
export const checkLocationAccuracy = jest.fn(async () => 'full');
1819
export const openPhotoPicker = jest.fn(async () => {});
@@ -70,6 +71,7 @@ export default {
7071
RESULTS,
7172

7273
canScheduleExactAlarms,
74+
canUseFullScreenIntent,
7375
check,
7476
checkLocationAccuracy,
7577
checkMultiple,

src/NativeRNPermissions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type NotificationsResponse = {
88

99
export interface Spec extends TurboModule {
1010
canScheduleExactAlarms(): Promise<boolean>;
11+
canUseFullScreenIntent(): Promise<boolean>;
1112
check(permission: string): Promise<string>;
1213
checkLocationAccuracy(): Promise<string>;
1314
checkMultiple(permissions: string[]): Promise<Object>;

src/contract.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import type {
1010

1111
export type Contract = {
1212
canScheduleExactAlarms(): Promise<boolean>;
13+
canUseFullScreenIntent(): Promise<boolean>;
1314
check(permission: Permission): Promise<PermissionStatus>;
1415
checkLocationAccuracy(): Promise<LocationAccuracy>;
1516
checkMultiple<P extends Permission[]>(
1617
permissions: P,
1718
): Promise<Record<P[number], PermissionStatus>>;
1819
checkNotifications(): Promise<NotificationsResponse>;
1920
openPhotoPicker(): Promise<void>;
20-
openSettings(type?: 'application' | 'alarms' | 'notifications'): Promise<void>;
21+
openSettings(type?: 'application' | 'alarms' | 'notifications' | 'fullscreen'): Promise<void>;
2122
request(permission: Permission, rationale?: Rationale): Promise<PermissionStatus>;
2223
requestLocationAccuracy(options: LocationAccuracyOptions): Promise<LocationAccuracy>;
2324
requestMultiple<P extends Permission[]>(

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export {RESULTS} from './results';
88
export * from './types';
99

1010
export const canScheduleExactAlarms = methods.canScheduleExactAlarms;
11+
export const canUseFullScreenIntent = methods.canUseFullScreenIntent;
1112
export const check = methods.check;
1213
export const checkLocationAccuracy = methods.checkLocationAccuracy;
1314
export const checkMultiple = methods.checkMultiple;
@@ -24,6 +25,7 @@ export default {
2425
RESULTS,
2526

2627
canScheduleExactAlarms,
28+
canUseFullScreenIntent,
2729
check,
2830
checkLocationAccuracy,
2931
checkMultiple,

src/methods.android.ts

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ const openSettings: Contract['openSettings'] = async (type = 'application') => {
4646
const canScheduleExactAlarms: Contract['canScheduleExactAlarms'] = () =>
4747
NativeModule.canScheduleExactAlarms();
4848

49+
const canUseFullScreenIntent: Contract['canUseFullScreenIntent'] = () =>
50+
NativeModule.canUseFullScreenIntent();
51+
4952
const check: Contract['check'] = async (permission) => {
5053
const status = (await NativeModule.check(permission)) as PermissionStatus;
5154
return status;
@@ -90,6 +93,7 @@ const requestMultiple: Contract['requestMultiple'] = (permissions) => {
9093

9194
export const methods: Contract = {
9295
canScheduleExactAlarms,
96+
canUseFullScreenIntent,
9397
check,
9498
checkLocationAccuracy,
9599
checkMultiple,

src/methods.ios.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {Contract} from './contract';
22
import NativeModule from './NativeRNPermissions';
33
import {LocationAccuracy, NotificationsResponse, PermissionStatus} from './types';
4-
import {canScheduleExactAlarms} from './unsupportedMethods';
4+
import {canScheduleExactAlarms, canUseFullScreenIntent} from './unsupportedMethods';
55
import {uniq} from './utils';
66

77
const openPhotoPicker: Contract['openPhotoPicker'] = async () => {
@@ -66,6 +66,7 @@ const requestMultiple: Contract['requestMultiple'] = async (permissions) => {
6666

6767
export const methods: Contract = {
6868
canScheduleExactAlarms,
69+
canUseFullScreenIntent,
6970
check,
7071
checkLocationAccuracy,
7172
checkMultiple,

src/methods.ts

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const checkMultiple: Contract['checkMultiple'] = async (permissions) => {
2727

2828
export const methods: Contract = {
2929
canScheduleExactAlarms: Promise.reject,
30+
canUseFullScreenIntent: Promise.reject,
3031
check,
3132
checkLocationAccuracy,
3233
checkMultiple,

src/methods.windows.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {Contract} from './contract';
33
import type {NotificationsResponse, PermissionStatus} from './types';
44
import {
55
canScheduleExactAlarms,
6+
canUseFullScreenIntent,
67
checkLocationAccuracy,
78
openPhotoPicker,
89
requestLocationAccuracy,
@@ -50,6 +51,7 @@ const requestMultiple: Contract['requestMultiple'] = async (permissions) => {
5051

5152
export const methods: Contract = {
5253
canScheduleExactAlarms,
54+
canUseFullScreenIntent,
5355
check,
5456
checkLocationAccuracy,
5557
checkMultiple,

src/unsupportedMethods.ts

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export const canScheduleExactAlarms: Contract['canScheduleExactAlarms'] = async
77
throw getUnsupportedError('Android', 12);
88
};
99

10+
export const canUseFullScreenIntent: Contract['canUseFullScreenIntent'] = async () => {
11+
throw getUnsupportedError('Android', 14);
12+
};
13+
1014
export const openPhotoPicker: Contract['openPhotoPicker'] = async () => {
1115
throw getUnsupportedError('iOS', 14);
1216
};

windows/RNPermissions/RNPermissions.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ void RNPermissions::RNPermissions::CanScheduleExactAlarms(React::ReactPromise<bo
4141
promise.Resolve(false);
4242
}
4343

44+
void RNPermissions::RNPermissions::CanUseFullScreenIntent(React::ReactPromise<bool>&& promise) noexcept {
45+
// no-op - Android only
46+
promise.Resolve(false);
47+
}
48+
4449
void RNPermissions::RNPermissions::CheckLocationAccuracy(React::ReactPromise<std::string>&& promise) noexcept {
4550
// no-op - iOS 14+ only
4651
promise.Resolve("N/A");

windows/RNPermissions/RNPermissions.h

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ struct RNPermissions
2929
REACT_METHOD(CanScheduleExactAlarms, L"canScheduleExactAlarms");
3030
void CanScheduleExactAlarms(React::ReactPromise<bool>&& promise) noexcept;
3131

32+
REACT_METHOD(CanUseFullScreenIntent, L"canUseFullScreenIntent");
33+
void CanUseFullScreenIntent(React::ReactPromise<bool>&& promise) noexcept;
34+
3235
REACT_METHOD(CheckLocationAccuracy, L"checkLocationAccuracy");
3336
void CheckLocationAccuracy(React::ReactPromise<std::string>&& promise) noexcept;
3437

windows/RNPermissions/codegen/NativeRNPermissionsSpec.g.h

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ inline winrt::Microsoft::ReactNative::FieldMap GetStructInfo(RNPermissionsSpec_N
2626
struct RNPermissionsSpec : winrt::Microsoft::ReactNative::TurboModuleSpec {
2727
static constexpr auto methods = std::tuple{
2828
Method<void(Promise<bool>) noexcept>{0, L"canScheduleExactAlarms"},
29+
Method<void(Promise<bool>) noexcept>{0, L"canUseFullScreenIntent"},
2930
Method<void(std::string, Promise<std::string>) noexcept>{1, L"check"},
3031
Method<void(Promise<std::string>) noexcept>{2, L"checkLocationAccuracy"},
3132
Method<void(std::vector<std::string>, Promise<::React::JSValue>) noexcept>{3, L"checkMultiple"},
@@ -48,6 +49,11 @@ struct RNPermissionsSpec : winrt::Microsoft::ReactNative::TurboModuleSpec {
4849
"canScheduleExactAlarms",
4950
" REACT_METHOD(canScheduleExactAlarms) void canScheduleExactAlarms(::React::ReactPromise<bool> &&result) noexcept { /* implementation */ }\n"
5051
" REACT_METHOD(canScheduleExactAlarms) static void canScheduleExactAlarms(::React::ReactPromise<bool> &&result) noexcept { /* implementation */ }\n");
52+
REACT_SHOW_METHOD_SPEC_ERRORS(
53+
0,
54+
"canUseFullScreenIntent",
55+
" REACT_METHOD(canUseFullScreenIntent) void canUseFullScreenIntent(::React::ReactPromise<bool> &&result) noexcept { /* implementation */ }\n"
56+
" REACT_METHOD(canUseFullScreenIntent) static void canUseFullScreenIntent(::React::ReactPromise<bool> &&result) noexcept { /* implementation */ }\n");
5157
REACT_SHOW_METHOD_SPEC_ERRORS(
5258
1,
5359
"check",

0 commit comments

Comments
 (0)