iOS:notification plugin
This commit is contained in:
parent
0087c5bda4
commit
9dabd3b1db
@ -32,7 +32,7 @@ dependencies {
|
||||
implementation "pub.doric:devkit:${rootProject.ext.Version}"
|
||||
implementation 'com.github.bumptech.glide:glide:4.10.0'
|
||||
implementation 'com.github.bumptech.glide:annotations:4.10.0'
|
||||
implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.3.1'
|
||||
implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.3.2'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0'
|
||||
|
@ -42,7 +42,7 @@ dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
api 'com.github.penfeizhou:jsc4a:0.1.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
|
||||
implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.3.1'
|
||||
implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.3.2'
|
||||
implementation 'jp.wasabeef:glide-transformations:4.1.0'
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
implementation "com.google.android.material:material:1.0.0"
|
||||
|
@ -55,8 +55,12 @@ public class NotificationPlugin extends DoricJavaPlugin {
|
||||
|
||||
@DoricMethod
|
||||
public void publish(JSObject args, DoricPromise promise) {
|
||||
String biz = args.getProperty("biz").asString().value();
|
||||
String name = args.getProperty("name").asString().value();
|
||||
JSValue bizValue = args.getProperty("biz");
|
||||
if (bizValue.isString()) {
|
||||
String biz = bizValue.asString().value();
|
||||
name = "__doric__" + biz + "#" + name;
|
||||
}
|
||||
String data = null;
|
||||
JSValue value = args.getProperty("data");
|
||||
if (value.isString()) {
|
||||
@ -67,7 +71,7 @@ public class NotificationPlugin extends DoricJavaPlugin {
|
||||
if (value.isBoolean()) {
|
||||
androidSystem = value.asBoolean().value();
|
||||
}
|
||||
Intent intent = new Intent("__doric__" + biz + "#" + name);
|
||||
Intent intent = new Intent(name);
|
||||
intent.putExtra("__doric_data__", data);
|
||||
if (androidSystem) {
|
||||
getDoricContext().getContext().sendBroadcast(intent);
|
||||
@ -80,8 +84,12 @@ public class NotificationPlugin extends DoricJavaPlugin {
|
||||
|
||||
@DoricMethod
|
||||
public void subscribe(JSObject args, DoricPromise promise) {
|
||||
String biz = args.getProperty("biz").asString().value();
|
||||
String name = args.getProperty("name").asString().value();
|
||||
JSValue bizValue = args.getProperty("biz");
|
||||
if (bizValue.isString()) {
|
||||
String biz = bizValue.asString().value();
|
||||
name = "__doric__" + biz + "#" + name;
|
||||
}
|
||||
final String callbackId = args.getProperty("callback").asString().value();
|
||||
JSValue value = args.getProperty("androidSystem");
|
||||
boolean androidSystem = false;
|
||||
@ -115,7 +123,7 @@ public class NotificationPlugin extends DoricJavaPlugin {
|
||||
}
|
||||
};
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction("__doric__" + biz + "#" + name);
|
||||
intentFilter.addAction(name);
|
||||
if (androidSystem) {
|
||||
getDoricContext().getContext().registerReceiver(receiver, intentFilter);
|
||||
systemReceivers.put(callbackId, receiver);
|
||||
|
@ -46,7 +46,7 @@
|
||||
#import "DoricInputNode.h"
|
||||
#import "DoricDraggableNode.h"
|
||||
#import "DoricLibrary.h"
|
||||
|
||||
#import "DoricNotificationPlugin.h"
|
||||
|
||||
@interface DoricLibraries : NSObject
|
||||
@property(nonatomic, strong) NSMutableSet <DoricLibrary *> *libraries;
|
||||
@ -109,6 +109,7 @@ - (void)innerRegister {
|
||||
[self registerNativePlugin:DoricNavBarPlugin.class withName:@"navbar"];
|
||||
[self registerNativePlugin:DoricPopoverPlugin.class withName:@"popover"];
|
||||
[self registerNativePlugin:DoricAnimatePlugin.class withName:@"animate"];
|
||||
[self registerNativePlugin:DoricNotificationPlugin.class withName:@"notification"];
|
||||
|
||||
[self registerViewNode:DoricStackNode.class withName:@"Stack"];
|
||||
[self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"];
|
||||
|
24
doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.h
Normal file
24
doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2020/1/8.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
@interface DoricNotificationPlugin : DoricNativePlugin
|
||||
@end
|
52
doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m
Normal file
52
doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2020/1/8.
|
||||
//
|
||||
|
||||
#import "DoricNotificationPlugin.h"
|
||||
|
||||
|
||||
@implementation DoricNotificationPlugin
|
||||
|
||||
- (void)publish:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
||||
NSString *notificationName = [NSString stringWithFormat:@"__doric__%@#%@", dic, promise];
|
||||
NSString *data = dic[@"data"];
|
||||
NSDictionary *dataDic = nil;
|
||||
if (data) {
|
||||
NSData *jsonData = [data dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError *err;
|
||||
dataDic = [NSJSONSerialization JSONObjectWithData:jsonData
|
||||
options:NSJSONReadingMutableContainers
|
||||
error:&err];
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:nil userInfo:dataDic];
|
||||
}
|
||||
|
||||
|
||||
- (void)subscribe:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
||||
NSString *notificationName = [NSString stringWithFormat:@"__doric__%@#%@", dic, promise];
|
||||
NSString *callbackId = dic[@"callback"];
|
||||
[[NSNotificationCenter defaultCenter] addObserverForName:notificationName
|
||||
object:nil
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification *note) {
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@end
|
4
doric-js/index.d.ts
vendored
4
doric-js/index.d.ts
vendored
@ -797,13 +797,13 @@ declare module 'doric/lib/src/native/notification' {
|
||||
import { BridgeContext } from "doric/lib/src/runtime/global";
|
||||
export function notification(context: BridgeContext): {
|
||||
publish: (args: {
|
||||
biz: string;
|
||||
biz?: string | undefined;
|
||||
name: string;
|
||||
data?: object | undefined;
|
||||
androidSystem?: boolean | undefined;
|
||||
}) => Promise<any>;
|
||||
subscribe: (args: {
|
||||
biz: string;
|
||||
biz?: string | undefined;
|
||||
name: string;
|
||||
callback: (data?: any) => void;
|
||||
androidSystem?: boolean | undefined;
|
||||
|
4
doric-js/lib/src/native/notification.d.ts
vendored
4
doric-js/lib/src/native/notification.d.ts
vendored
@ -1,13 +1,13 @@
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
export declare function notification(context: BridgeContext): {
|
||||
publish: (args: {
|
||||
biz: string;
|
||||
biz?: string | undefined;
|
||||
name: string;
|
||||
data?: object | undefined;
|
||||
androidSystem?: boolean | undefined;
|
||||
}) => Promise<any>;
|
||||
subscribe: (args: {
|
||||
biz: string;
|
||||
biz?: string | undefined;
|
||||
name: string;
|
||||
callback: (data?: any) => void;
|
||||
androidSystem?: boolean | undefined;
|
||||
|
@ -16,13 +16,13 @@
|
||||
import { BridgeContext } from "../runtime/global"
|
||||
export function notification(context: BridgeContext) {
|
||||
return {
|
||||
publish: (args: { biz: string, name: string, data?: object, androidSystem?: boolean }) => {
|
||||
publish: (args: { biz?: string, name: string, data?: object, androidSystem?: boolean }) => {
|
||||
if (args.data !== undefined) {
|
||||
(args as any).data = JSON.stringify(args.data)
|
||||
}
|
||||
return context.notification.publish(args)
|
||||
},
|
||||
subscribe: (args: { biz: string, name: string, callback: (data?: any) => void, androidSystem?: boolean }) => {
|
||||
subscribe: (args: { biz?: string, name: string, callback: (data?: any) => void, androidSystem?: boolean }) => {
|
||||
(args as any).callback = (context as any).function2Id(args.callback)
|
||||
return context.notification.subscribe(args) as Promise<string>
|
||||
},
|
||||
|
Reference in New Issue
Block a user