Skip to content

Commit 9bfdf78

Browse files
authored
Merge pull request #2 from nilavanraj/CustomNotification
version 0.8 changes add
2 parents 7d82f1f + dda6e9a commit 9bfdf78

File tree

9 files changed

+123
-34
lines changed

9 files changed

+123
-34
lines changed
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
package com.reactnativecustomtimernotification
2-
3-
class CNException {
4-
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class CustomNotificationModule: ReactContextBaseJavaModule {
5151
@ReactMethod
5252
fun CustomNotification(objectData:ReadableMap,callback: Callback) {
5353
try{
54+
imageCount = 0;
5455
val payload = objectData.getString(Constants.NOTIFICATION.PAYLOAD);
5556
val title = objectData.getString(Constants.NOTIFICATION.TITLE);
5657
val body = objectData.getString(Constants.NOTIFICATION.BODY);
@@ -77,6 +78,8 @@ class CustomNotificationModule: ReactContextBaseJavaModule {
7778
for (i in 0..(View?.size()?.minus(1) ?: 0)) {
7879
val item = View?.getMap(i);
7980
if(item!=null && item.hasKey(Constants.VIEW.TYPE) && item.getInt(Constants.VIEW.TYPE)==1){
81+
Log.i("imageCount",imageCount.toString())
82+
8083
setImageView(item, notificationLayout,imageCount);
8184
imageCount+=1;
8285
}
@@ -153,6 +156,7 @@ class CustomNotificationModule: ReactContextBaseJavaModule {
153156
bold = item.getInt(Constants.VIEW.BOLD)
154157
}
155158
val s = SpannableString(item?.getString("name"))
159+
Typeface.BOLD
156160
s.setSpan(StyleSpan(bold), 0, s.length, 0)
157161
textView.setTextViewText(R.id.textView1, s)
158162

@@ -207,9 +211,8 @@ class CustomNotificationModule: ReactContextBaseJavaModule {
207211
handler.postDelayed({
208212
notificationLayout.setChronometerCountDown(R.id.timerCustom, true);
209213
notificationLayout.setChronometer(R.id.timerCustom, remainingTime, ("%tM:%tS"), false);
210-
if(item.getBoolean(Constants.VIEW.HIDE))
211-
notificationLayout.setViewVisibility (R.id.timerCustom, View.INVISIBLE)
212-
notificationBuilder.setCustomContentView(notificationLayout)
214+
notificationLayout.setViewVisibility (R.id.timerCustomLayout, View.GONE)
215+
notificationBuilder.setCustomContentView(notificationLayout)
213216
notificationManager.notify(id,notificationBuilder.build())
214217
}, Math.abs(elapsed))
215218
}

android/src/main/res/layout/chronometer_view_layout.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:orientation="vertical"
4+
android:id="@+id/timerCustomLayout"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent">
67
<Chronometer

example/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ buildscript {
66
compileSdkVersion = 29
77
targetSdkVersion = 29
88

9-
ndkVersion = "21.4.7075529"
9+
ndkVersion = "21.1.6352462"
1010
}
1111
repositories {
1212
google()
1313
mavenCentral()
1414
jcenter()
1515
}
1616
dependencies {
17-
classpath 'com.android.tools.build:gradle:4.0.0'
17+
classpath 'com.android.tools.build:gradle:4.1.0'
1818

1919
// NOTE: Do not place your application dependencies here; they belong
2020
// in the individual module build.gradle files
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

example/src/App.tsx

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import * as React from 'react';
2-
2+
import { Button } from 'react-native';
33
import {
44
TimerNotification,
55
RemoveTimer,
66
onEvent,
77
CustomNotification,
8+
TYPES,
9+
FB_TYPE,
810
} from 'react-native-custom-timer-notification';
9-
import { Dimensions } from 'react-native';
10-
import { image, image2 } from './image';
11-
const windowWidth = Dimensions.get('window').width;
12-
const windowHeight = Dimensions.get('window').height;
11+
import { image } from './image';
1312

1413
onEvent((event: any) => {
1514
console.log(event);
1615
});
1716

1817
export default function App() {
19-
React.useEffect(() => {
18+
const CN = React.useCallback(() => {
2019
CustomNotification(
2120
{
2221
eventData: JSON.stringify('notificationOpen?.data'),
@@ -28,8 +27,8 @@ export default function App() {
2827
{
2928
name: 'Limited Sales',
3029
size: 20,
31-
type: 2,
32-
bold: 3,
30+
type: TYPES.Text,
31+
bold: FB_TYPE.BOLD_ITALIC,
3332
PaddingLeft: 10,
3433
PaddingTop: 50,
3534
PaddingRight: 0,
@@ -38,9 +37,8 @@ export default function App() {
3837
color: '#ed1a45',
3938
},
4039
{
41-
size: 50,
4240
uri: image,
43-
type: 1,
41+
type: TYPES.Image,
4442
PaddingLeft: 0,
4543
PaddingTop: 0,
4644
PaddingRight: 0,
@@ -49,8 +47,8 @@ export default function App() {
4947
{
5048
name: 'Buy now',
5149
size: 30,
52-
type: 2,
53-
bold: 3,
50+
type: TYPES.Text,
51+
bold: FB_TYPE.BOLD_ITALIC,
5452
PaddingLeft: 10,
5553
PaddingTop: 100,
5654
PaddingRight: 0,
@@ -59,11 +57,10 @@ export default function App() {
5957
color: '#fbd335',
6058
},
6159
{
62-
type: 3,
60+
type: TYPES.Cronometer,
61+
size: 30,
6362
ZeroTime: new Date(Date.now() + 20000),
6463
PaddingLeft: 800,
65-
hide: true,
66-
size: 25,
6764
color: '#0000FF',
6865
PaddingTop: 0,
6966
PaddingRight: 0,
@@ -77,5 +74,30 @@ export default function App() {
7774
);
7875
}, []);
7976

80-
return <></>;
77+
const TN = React.useCallback(() => {
78+
TimerNotification({
79+
payload: JSON.stringify('notificationOpen?.data'),
80+
title: 'My notification',
81+
body: 'Much longer text that cannot fit one line... ',
82+
id: 160211114,
83+
remove: false, // optional
84+
foreground: false,
85+
date: new Date(Date.now() + 20000),
86+
isCountDown: true, // false for positive timer
87+
setCustomContentView: true, // optional
88+
});
89+
}, []);
90+
91+
return (
92+
<>
93+
<Button title="Custom Notification" onPress={CN} />
94+
<Button title="Timer Notification" onPress={TN} />
95+
<Button
96+
title="remove"
97+
onPress={() => {
98+
RemoveTimer(1);
99+
}}
100+
/>
101+
</>
102+
);
81103
}

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.7.0",
3+
"version": "0.8.0",
44
"description": "custom timer notification",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

src/index.d.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
interface View {
2+
name?: string;
3+
size?: number;
4+
type: number;
5+
bold?: number;
6+
PaddingLeft: number;
7+
PaddingTop: number;
8+
PaddingRight: number;
9+
PaddingBottom: number;
10+
setViewVisibility?: boolean;
11+
color?: string;
12+
uri?: string;
13+
ZeroTime?: date | null;
14+
hide?: boolean;
15+
}
16+
interface CNViewItems extends Array<View> {}
17+
18+
interface CN {
19+
eventData: string;
20+
title: string;
21+
body: string;
22+
id: number;
23+
View: CNViewItems;
24+
}
25+
interface Type {
26+
Image: number;
27+
Text: number;
28+
Cronometer: number;
29+
}
30+
interface FB_TYPE {
31+
NORMAL: number;
32+
BOLD: number;
33+
ITALIC: number;
34+
BOLD_ITALIC: number;
35+
}
36+
interface CTN {
37+
payload: string;
38+
title: string;
39+
body: string;
40+
remove?: boolean;
41+
foreground: boolean;
42+
id: number;
43+
date?: date;
44+
isCountDown: boolean;
45+
setCustomContentView?: boolean;
46+
}
47+
48+
export function onEvent(listener: function): Void;
49+
export function CustomNotification(a: CN, cb: function): Void;
50+
export function TimerNotification(a: CTN): Void;
51+
export function RemoveTimer(n: number);
52+
export const TYPES: Type;
53+
export const FB_TYPE: FB_TYPE;

src/index.tsx renamed to src/index.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NativeModules, Platform, DeviceEventEmitter } from 'react-native';
2-
const parseDate = (rawDate: any) => {
2+
const parseDate = (rawDate) => {
33
let hours;
44
let day;
55
let month;
@@ -51,15 +51,15 @@ const CustomNotificationModule = NativeModules.CustomNotificationModule
5151
},
5252
}
5353
);
54-
export function TimerNotification(a: object): any {
55-
const data: any = a;
54+
export function TimerNotification(a) {
55+
const data = a;
5656
data.date = parseDate(data.date);
5757

5858
if (Platform.OS === 'android')
5959
return CustomTimerNotification.TimerNotification(data);
6060
return null;
6161
}
62-
export function RemoveTimer(a: number, b: Boolean = false): any {
62+
export function RemoveTimer(a, b = false) {
6363
const payload = {
6464
id: a,
6565
foreground: b || false,
@@ -68,8 +68,8 @@ export function RemoveTimer(a: number, b: Boolean = false): any {
6868
CustomTimerNotification.RemoveTimer(payload);
6969
}
7070

71-
export function CustomNotification(a: object, cb: any): any {
72-
const data: any = a;
71+
export function CustomNotification(a, cb) {
72+
const data = a;
7373

7474
data.View = data.View.map((item) => {
7575
if (item.type == 3)
@@ -84,12 +84,25 @@ export function CustomNotification(a: object, cb: any): any {
8484
});
8585

8686
if (Platform.OS === 'android')
87-
return NativeModules.CustomNotificationModule.CustomNotification(data, cb);
87+
return CustomNotificationModule.CustomNotification(data, cb);
8888
return null;
8989
}
9090

91-
export function onEvent(listener: Function): void {
91+
export function onEvent(listener) {
9292
DeviceEventEmitter.addListener('notificationClick', (event) =>
9393
listener(event)
9494
);
9595
}
96+
97+
export const TYPES = {
98+
Image: 1,
99+
Text: 2,
100+
Cronometer: 3,
101+
};
102+
103+
export const FB_TYPE = {
104+
NORMAL: 0,
105+
BOLD: 1,
106+
ITALIC: 2,
107+
BOLD_ITALIC: 3,
108+
};

0 commit comments

Comments
 (0)