Skip to content

Commit 293651a

Browse files
committed
added full custom notification
1 parent 11d6269 commit 293651a

File tree

10 files changed

+289
-289
lines changed

10 files changed

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

33
object Constants {
4-
const val TABLE_USER_ATTRIBUTE_EMPID = "teamImg1"
5-
const val TABLE_USER_ATTRIBUTE_DATA = "data"
4+
object NOTIFICATION {
5+
const val BODY = "body"
6+
const val TITLE = "title"
7+
const val PAYLOAD = "payload"
8+
const val ID = "id"
9+
const val IS_COUNT = "isCount"
10+
const val IMAGEVIEW = "ImageView"
11+
const val VIEW = "View"
12+
const val ZEROTIME = "ZeroTime"
13+
14+
}
15+
object PADDING {
16+
const val TOP = "PaddingTop"
17+
const val LEFT = "PaddingLeft"
18+
const val RIGHT = "PaddingRight"
19+
const val BOTTOM = "PaddingBottom"
20+
21+
}
22+
object VIEW {
23+
const val SIZE = "size"
24+
const val TYPE = "type"
25+
const val HIDE = "hide"
26+
const val BOLD = "bold"
27+
28+
29+
}
30+
631
}

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

Lines changed: 155 additions & 147 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
<Chronometer
7+
android:id="@+id/timerCustom"
8+
style="@style/TextAppearance.Compat.Notification.Title"
9+
android:layout_weight="5"
10+
android:layout_width="wrap_content"
11+
android:layout_height="match_parent"
12+
android:gravity="right|center_vertical"
13+
android:maxLines="1"
14+
android:text="timerCustom"
15+
android:textSize="20dp" />
16+
17+
</LinearLayout>
Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
4-
android:layout_height="64dp"
5-
android:orientation="vertical"
6-
android:id="@+id/main"
7-
android:layout_marginLeft="45dp"
4+
android:layout_height="120dp"
85

6+
android:orientation="vertical"
7+
android:id="@+id/main"
98
>
109

11-
12-
13-
14-
15-
<!-- DYNAMIC TEXT-->
16-
<LinearLayout
17-
android:layout_width="match_parent"
18-
android:layout_height="match_parent"
19-
android:layout_marginLeft="42dp"
20-
>
21-
<ImageView
22-
android:id="@+id/image"
23-
android:layout_width="25dp"
24-
android:layout_height="20dp"
25-
android:layout_marginTop="35dp"/>
26-
27-
<TextView
28-
android:id="@+id/tv_title"
29-
style="@style/TextAppearance.Compat.Notification.Title"
30-
android:layout_width="wrap_content"
31-
android:layout_height="20dp"
32-
android:layout_marginTop="35dp"
33-
android:background="@null"
34-
android:ellipsize="end"
35-
android:maxLines="1"
36-
android:textColor="#ffff" />
37-
38-
39-
40-
<TextView
41-
android:id="@+id/tv_content"
42-
style="@style/TextAppearance.Compat.Notification.Title"
43-
android:layout_width="wrap_content"
44-
android:layout_height="20dp"
45-
android:layout_marginTop="35dp"
46-
android:background="@null"
47-
android:ellipsize="end"
48-
android:maxLines="1"
49-
android:textColor="#ffff" />
50-
51-
<ImageView
52-
android:id="@+id/image1"
53-
android:layout_width="30dp"
54-
android:layout_height="20dp"
55-
android:layout_marginTop="35dp"/>
56-
57-
</LinearLayout>
58-
<!--PICK NOW-->
59-
<RelativeLayout
60-
android:layout_width="fill_parent"
61-
android:layout_height="fill_parent">
62-
63-
64-
</RelativeLayout>
6510
</RelativeLayout>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
android:layout_height="match_parent"
66
android:id="@+id/LinearLayout"
77
>
8-
<TextView
8+
<TextView
99
android:id="@+id/textView1"
1010
android:layout_width="wrap_content"
1111
android:layout_height="wrap_content"
1212
android:text="TextView"
13-
android:layout_marginLeft="45dp"
1413
android:textAppearance="?android:attr/textAppearanceLarge" />
1514
</LinearLayout>
1615

example/src/58332892.jpg

-30.8 KB
Binary file not shown.

example/src/App.tsx

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,89 +4,77 @@ import {
44
TimerNotification,
55
RemoveTimer,
66
onEvent,
7-
multiply,
7+
CustomNotification,
88
} from 'react-native-custom-timer-notification';
9-
import { image } from './image';
10-
const image1 = `iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=`
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;
13+
1114
onEvent((event: any) => {
1215
console.log(event);
1316
});
17+
1418
export default function App() {
1519
React.useEffect(() => {
16-
multiply(
20+
CustomNotification(
1721
{
18-
teamImg1:
19-
'https://s3.ap-south-1.amazonaws.com/leaguex/team-images/bblw/MLSW.png',
20-
teamImg2:
21-
'https://s3.ap-south-1.amazonaws.com/leaguex/team-images/bblw/MLSW.png',
2222
eventData: JSON.stringify('notificationOpen?.data'),
2323
title: 'notificationOpen.data.title',
2424
body: ' notificationOpen.data.body',
25-
id: 160211114,
26-
TextView: [
25+
id: 1,
26+
27+
View: [
2728
{
28-
name: 'nilavan1',
29-
size: 35,
30-
PaddingLeft: 0,
31-
PaddingTop: 0,
29+
name: 'Limited Sales',
30+
size: 20,
31+
type: 2,
32+
bold: 3,
33+
PaddingLeft: 10,
34+
PaddingTop: 50,
3235
PaddingRight: 0,
33-
PaddingBottom: 100,
36+
PaddingBottom: 0,
3437
setViewVisibility: false,
38+
color: '#ed1a45',
3539
},
3640
{
37-
name: 'nilavan1',
38-
size: 25,
41+
size: 50,
42+
uri: image,
43+
type: 1,
3944
PaddingLeft: 0,
40-
PaddingTop: 10,
45+
PaddingTop: 0,
4146
PaddingRight: 0,
42-
PaddingBottom: 100,
43-
setViewVisibility: false,
47+
PaddingBottom: 0,
4448
},
45-
],
46-
ImageView: [
4749
{
48-
size: 50,
49-
url:"iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII",
50-
PaddingLeft: -100,
51-
PaddingTop: 0,
50+
name: 'Buy now',
51+
size: 30,
52+
type: 2,
53+
bold: 3,
54+
PaddingLeft: 10,
55+
PaddingTop: 100,
5256
PaddingRight: 0,
5357
PaddingBottom: 0,
58+
setViewVisibility: false,
59+
color: '#fbd335',
5460
},
5561
{
56-
size: 50,
57-
url: image1,
58-
PaddingLeft: 200,
62+
type: 3,
63+
ZeroTime: new Date(Date.now() + 20000),
64+
PaddingLeft: 800,
65+
hide: true,
66+
size: 25,
67+
color: '#0000FF',
5968
PaddingTop: 0,
6069
PaddingRight: 0,
6170
PaddingBottom: 0,
62-
}
63-
71+
},
6472
],
65-
toFixed: function (fractionDigits?: number | undefined): string {
66-
throw new Error('Function not implemented.');
67-
},
68-
toExponential: function (fractionDigits?: number | undefined): string {
69-
throw new Error('Function not implemented.');
70-
},
71-
toPrecision: function (precision?: number | undefined): string {
72-
throw new Error('Function not implemented.');
73-
},
7473
},
7574
(e: any) => {
7675
console.log(e);
7776
}
7877
);
79-
// TimerNotification({
80-
// payload: JSON.stringify('notificationOpen?.data'),
81-
// title: 'My notification',
82-
// body: 'Much longer text that cannot fit one line... ',
83-
// id: 160211114,
84-
// remove: false, // optional
85-
// foreground: false,
86-
// date: new Date(Date.now() + 20000),
87-
// isCountDown: true,
88-
// setCustomContentView: true, // optional
89-
// });
9078
}, []);
9179

9280
return <></>;

example/src/image.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.tsx

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
import { NativeModules, Platform, DeviceEventEmitter } from 'react-native';
2+
const parseDate = (rawDate: any) => {
3+
let hours;
4+
let day;
5+
let month;
26

7+
if (rawDate.getHours().toString().length === 1) {
8+
hours = `0${rawDate.getHours()}`;
9+
} else {
10+
hours = `${rawDate.getHours()}`;
11+
}
12+
13+
if (rawDate.getDate().toString().length === 1) {
14+
day = `0${rawDate.getDate()}`;
15+
} else {
16+
day = `${rawDate.getDate()}`;
17+
}
18+
19+
if (rawDate.getMonth().toString().length === 1) {
20+
month = `0${rawDate.getMonth() + 1}`;
21+
} else {
22+
month = `${rawDate.getMonth() + 1}`;
23+
}
24+
25+
return `${day}-${month}-${rawDate.getFullYear()} ${hours}:${rawDate.getMinutes()}:${rawDate.getSeconds()}`;
26+
};
327
const LINKING_ERROR =
428
`The package 'react-native-custom-timer-notification' doesn't seem to be linked. Make sure: \n\n` +
529
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
@@ -28,31 +52,6 @@ const CustomNotificationModule = NativeModules.CustomNotificationModule
2852
}
2953
);
3054
export function TimerNotification(a: object): any {
31-
const parseDate = (rawDate: any) => {
32-
let hours;
33-
let day;
34-
let month;
35-
36-
if (rawDate.getHours().toString().length === 1) {
37-
hours = `0${rawDate.getHours()}`;
38-
} else {
39-
hours = `${rawDate.getHours()}`;
40-
}
41-
42-
if (rawDate.getDate().toString().length === 1) {
43-
day = `0${rawDate.getDate()}`;
44-
} else {
45-
day = `${rawDate.getDate()}`;
46-
}
47-
48-
if (rawDate.getMonth().toString().length === 1) {
49-
month = `0${rawDate.getMonth() + 1}`;
50-
} else {
51-
month = `${rawDate.getMonth() + 1}`;
52-
}
53-
54-
return `${day}-${month}-${rawDate.getFullYear()} ${hours}:${rawDate.getMinutes()}:${rawDate.getSeconds()}`;
55-
};
5655
const data: any = a;
5756
data.date = parseDate(data.date);
5857

@@ -69,9 +68,24 @@ export function RemoveTimer(a: number, b: Boolean = false): any {
6968
CustomTimerNotification.RemoveTimer(payload);
7069
}
7170

72-
export function multiply(a: number, b: number): Promise<number> {
73-
console.log(CustomNotificationModule);
74-
return CustomNotificationModule.multiply(a, b);
71+
export function CustomNotification(a: object, cb: any): any {
72+
const data: any = a;
73+
74+
data.View = data.View.map((item) => {
75+
if (item.type == 3)
76+
return {
77+
...item,
78+
ZeroTime: parseDate(item.ZeroTime),
79+
};
80+
81+
return {
82+
...item,
83+
};
84+
});
85+
86+
if (Platform.OS === 'android')
87+
return NativeModules.CustomNotificationModule.CustomNotification(data, cb);
88+
return null;
7589
}
7690

7791
export function onEvent(listener: Function): void {

0 commit comments

Comments
 (0)