Skip to content

Commit

Permalink
fix: isAppInForeground (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
mieszko4 authored Dec 5, 2022
1 parent 6dfc923 commit 4f07f48
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,9 @@ static boolean isAppInForeground() {
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
&& appProcess.processName.equals(packageName)) {
ReactContext reactContext;

try {
reactContext = (ReactContext) context;
} catch (ClassCastException exception) {
return true;
ReactContext reactContext = getReactContext();
if (reactContext == null) {
return false;
}

return reactContext.getLifecycleState() == LifecycleState.RESUMED;
Expand Down
2 changes: 1 addition & 1 deletion tests_react_native/example/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
AndroidLaunchActivityFlag,
AndroidCategory,
AndroidImportance,
AndroidFlags,
} from '@notifee/react-native';
import { AndroidFlags } from '@notifee/react-native/src';

export const notifications: { key: string; notification: Notification | Notification[] }[] = [
{
Expand Down
36 changes: 36 additions & 0 deletions tests_react_native/specs/notification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,42 @@ export function NotificationSpec(spec: TestScope): void {
});
},
);

spec.it('displays a notification with a quick action without input', async function () {
return new Promise(async (resolve, reject) => {
return notifee
.displayNotification({
title: '',
body: '',
android: {
channelId: 'high',
actions: [
{
title: 'First Action',
pressAction: {
id: 'first_action',
},
},
],
},
})
.then(id => {
expect(id).equals(id);
resolve();
})
.catch(e => {
reject(e);
});
});

// Manual steps:
// 1. Minimize app
// 2. Open notification drawer
// 3. Tap on 'First Action'
// 4. Make sure you see:
// > WARN Received a ACTION_PRESS Background event in JS mode.
// > WARN Notification Cancelled first_action
});
});
});

Expand Down

0 comments on commit 4f07f48

Please sign in to comment.