Skip to content

Commit f21d0eb

Browse files
committed
bug fix Listener and layout file name change
1 parent 5e33824 commit f21d0eb

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# react-native-custom-timer-notification
22

3-
custom timer notification for react native 🔔
3+
Custom timer notification for React Native Android 🔔
44
![ezgif com-gif-maker](https://user-images.githubusercontent.com/58332892/166133982-effe321c-a0fd-4315-bb29-cc7ee29d0bd4.gif)
55

66

@@ -29,13 +29,13 @@ AndroidManifest
2929
```sec``` Time in seconds <br>
3030

3131
```js
32-
import { TimerNotification } from "react-native-custom-timer-notification";
32+
import { TimerNotification, onEvent } from "react-native-custom-timer-notification";
3333

3434
// ...
3535
// onclick and cancel listner
36-
DeviceEventEmitter.addListener("notificationClick",event=>{
36+
onEvent(event=>{
3737
console.log(event)
38-
})
38+
});
3939

4040
const result = await TimerNotification({
4141
payload: JSON.stringify("notificationOpen?.data"),

android/src/main/java/com/reactnativecustomtimernotification/CustomTimerNotificationModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class CustomTimerNotificationModule: ReactContextBaseJavaModule {
101101
val onDismissPendingIntent =
102102
PendingIntent.getBroadcast(myContext, 0, onCancelIntent, 0)
103103

104-
val notificationLayout = RemoteViews(packageName, R.layout.notification_collapsed);
104+
val notificationLayout = RemoteViews(packageName, R.layout.notification_open);
105105
notificationLayout.setTextViewText(R.id.title,title)
106106
notificationLayout.setTextViewText(R.id.text,body)
107107
notificationLayout.setTextViewText(R.id.timer,remainingTime)

android/src/main/java/com/reactnativecustomtimernotification/ForegroundService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ForegroundService : Service() {
6666
val onDismissPendingIntent =
6767
PendingIntent.getBroadcast(this, 0, onCancelIntent, 0)
6868

69-
val notificationLayout = RemoteViews(packageName, R.layout.notification_collapsed);
69+
val notificationLayout = RemoteViews(packageName, R.layout.notification_open);
7070
notificationLayout.setTextViewText(R.id.title,title)
7171
notificationLayout.setTextViewText(R.id.text,body)
7272
notificationLayout.setTextViewText(R.id.timer,remainingTime)

example/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as React from 'react';
22

33
import { StyleSheet, View, Text,DeviceEventEmitter } from 'react-native';
4-
import { TimerNotification } from 'react-native-custom-timer-notification';
5-
DeviceEventEmitter.addListener("notificationClick",event=>{
4+
import { TimerNotification,onEvent } from 'react-native-custom-timer-notification';
5+
onEvent(event=>{
66
console.log(event)
7-
})
7+
});
88
export default function App() {
99
const [result, setResult] = React.useState<number | undefined>();
1010

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-custom-timer-notification",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "custom timer notification",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

src/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NativeModules, Platform } from 'react-native';
1+
import { NativeModules, Platform, DeviceEventEmitter } from 'react-native';
22

33
const LINKING_ERROR =
44
`The package 'react-native-custom-timer-notification' doesn't seem to be linked. Make sure: \n\n` +
@@ -17,6 +17,14 @@ const CustomTimerNotification = NativeModules.CustomTimerNotification
1717
}
1818
);
1919

20-
export function TimerNotification(a: object): Promise<number> {
21-
return CustomTimerNotification.TimerNotification(a);
20+
export function TimerNotification(a: object): any {
21+
if (Platform.OS === 'android')
22+
return CustomTimerNotification.TimerNotification(a);
23+
return null;
24+
}
25+
26+
export function onEvent(listener: Function): void {
27+
DeviceEventEmitter.addListener('notificationClick', (event) =>
28+
listener(event)
29+
);
2230
}

0 commit comments

Comments
 (0)