Commit cd1b3c00 authored by hl's avatar hl

update

parent 0b3dc5bc
......@@ -4,26 +4,21 @@ import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
const { RNGeekImageEditor, ReactNativeSending } = NativeModules;
function edit(json, callback) {
if (Platform.OS === 'android') {
let loadingManagerEmitter = new NativeEventEmitter(ReactNativeSending)
loadingManagerEmitter.addListener('ImgEditEvent', (data) => {
console.log('data')
console.log(data)
try {
if (data.result) {
let backData = JSON.parse(data.result)
// this._getNotice(backData)
callback(backData)
}
} catch (err) {
//Toast.warn('返回数据错误!')
console.log(err)
let loadingManagerEmitter = new NativeEventEmitter(ReactNativeSending)
loadingManagerEmitter.addListener('ImgEditEvent', (data) => {
console.log('data')
console.log(data)
try {
if (data.result) {
let backData = JSON.parse(data.result)
callback(backData)
}
});
RNGeekImageEditor.edit(json)
} else {
RNGeekImageEditor.edit(json, callback)
}
} catch (err) {
//Toast.warn('返回数据错误!')
console.log(err)
}
});
RNGeekImageEditor.edit(json)
}
export default RNGeekImageEditor;
......
......@@ -16,9 +16,11 @@ NS_ASSUME_NONNULL_BEGIN
@interface ImageEditorManger : NSObject
+ (instancetype) shared;
@property (nonatomic, readonly , copy) ImageEditedCallBack callback;
- (void) showImages:(NSDictionary *)params cb:(ImageEditedCallBack)cb;
- (void) showImages:(NSDictionary *)params;
@end
......
......@@ -21,13 +21,24 @@
@end
ImageEditorManger *manager = nil;
@implementation ImageEditorManger
- (void) showImages:(NSDictionary *)params cb:(ImageEditedCallBack)cb {
+ (instancetype) shared {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (!manager) {
manager = [[ImageEditorManger alloc] init];
}
});
return manager;
}
- (void) showImages:(NSDictionary *)params {
ImageEditorModel *model = [ImageEditorModel yy_modelWithJSON:params];
self.editModel = model;
[self showBrower:model];
_callback = cb;
}
- (void) showBrower:(ImageEditorModel *)model {
......@@ -107,7 +118,7 @@
EditorImageModel *model =[self.editModel.images objectAtIndex:index];
model.editedImage = [Utils saveImageTosandBox:photoEdit.editPreviewImage];
self.editModel.questions = [ImageEditorModel yy_modelWithJSON:photoEditingVC.data].questions;
self.callback(self.editModel);
[[NSNotificationCenter defaultCenter] postNotificationName:@"event-emitted" object:[self.editModel yy_modelToJSONString]];
[photoEditingVC dismissViewControllerAnimated:true completion:nil];
}
......
......@@ -17,15 +17,10 @@
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(edit:(NSString *)json result:(RCTResponseSenderBlock)block) {
RCT_EXPORT_METHOD(edit:(NSString *)json) {
dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary *dic = [Utils dictionaryWithJsonString:json];
[[[ImageEditorManger alloc] init] showImages:dic cb:^(ImageEditorModel * _Nullable editedParams) {
NSDictionary *result = [editedParams yy_modelToJSONObject];
if (block) {
block(@[result]);
}
}];
[[[ImageEditorManger ] showImages:dic];
});
}
......
......@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
70AA071C2428964500913FEB /* Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 70AA071B2428964500913FEB /* Utils.m */; };
70B1D2852428DCBB0019CC42 /* ReactNativeSending.m in Sources */ = {isa = PBXBuildFile; fileRef = 70B1D2842428DCBB0019CC42 /* ReactNativeSending.m */; };
907D55EE8B15049A51D1C8F0 /* Pods_RNGeekImageEditor.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 64BE65D6A85DC61B6DBBD41A /* Pods_RNGeekImageEditor.framework */; };
DC88F9C3241A328F0074E2BD /* ImageEditorManger.m in Sources */ = {isa = PBXBuildFile; fileRef = DC88F9C0241A328E0074E2BD /* ImageEditorManger.m */; };
DC88F9C4241A328F0074E2BD /* ImageEditorModel.m in Sources */ = {isa = PBXBuildFile; fileRef = DC88F9C1241A328E0074E2BD /* ImageEditorModel.m */; };
......@@ -254,6 +255,8 @@
70AA07EA2428C82A00913FEB /* 错误-选中.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "错误-选中.png"; sourceTree = "<group>"; };
70AA07EB2428C82A00913FEB /* 半对-选中.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "半对-选中.png"; sourceTree = "<group>"; };
70AA07EC2428C82A00913FEB /* CheckView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CheckView.h; sourceTree = "<group>"; };
70B1D2832428DCBB0019CC42 /* ReactNativeSending.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReactNativeSending.h; sourceTree = "<group>"; };
70B1D2842428DCBB0019CC42 /* ReactNativeSending.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReactNativeSending.m; sourceTree = "<group>"; };
96C07757F20464F4AC5B060A /* Pods-RNGeekImageEditor.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNGeekImageEditor.debug.xcconfig"; path = "Target Support Files/Pods-RNGeekImageEditor/Pods-RNGeekImageEditor.debug.xcconfig"; sourceTree = "<group>"; };
B2E39BAE03E14EB914ABA09D /* Pods-RNGeekImageEditor.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNGeekImageEditor.release.xcconfig"; path = "Target Support Files/Pods-RNGeekImageEditor/Pods-RNGeekImageEditor.release.xcconfig"; sourceTree = "<group>"; };
DC88F9BF241A328E0074E2BD /* ImageEditorModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageEditorModel.h; sourceTree = "<group>"; };
......@@ -295,6 +298,8 @@
58B511D21A9E6C8500147676 = {
isa = PBXGroup;
children = (
70B1D2832428DCBB0019CC42 /* ReactNativeSending.h */,
70B1D2842428DCBB0019CC42 /* ReactNativeSending.m */,
DC88FCE2241A3D710074E2BD /* RNGeekImageEditor.h */,
DC88FCE3241A3D710074E2BD /* RNGeekImageEditor.m */,
DC88F9C2241A328F0074E2BD /* ImageEditorManger.h */,
......@@ -1019,6 +1024,7 @@
DC88FCE4241A3D710074E2BD /* RNGeekImageEditor.m in Sources */,
DC88F9C3241A328F0074E2BD /* ImageEditorManger.m in Sources */,
DC88F9C4241A328F0074E2BD /* ImageEditorModel.m in Sources */,
70B1D2852428DCBB0019CC42 /* ReactNativeSending.m in Sources */,
70AA071C2428964500913FEB /* Utils.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
......
//
// ReactNativeSending.h
// RNGeekImageEditor
//
// Created by hl on 2020/3/23.
// Copyright © 2020 Facebook. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
NS_ASSUME_NONNULL_BEGIN
@interface ReactNativeSending : RCTEventEmitter<RCTBridgeModule>
@end
NS_ASSUME_NONNULL_END
//
// ReactNativeSending.m
// RNGeekImageEditor
//
// Created by hl on 2020/3/23.
// Copyright © 2020 Facebook. All rights reserved.
//
#import "ReactNativeSending.h"
@implementation ReactNativeSending
RCT_EXPORT_MODULE();
- (NSArray<NSString *> *)supportedEvents {
return @[@"ImgEditEvent"]; //这里返回的将是你要发送的消息名的数组。
}
- (void)startObserving
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(emitEventInternal:)
name:@"event-emitted"
object:nil];
}
- (void)stopObserving
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)emitEventInternal:(NSNotification *)notification
{
[self sendEventWithName:@"ImgEditEvent"
body:notification.object];
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment