Commit cd1b3c00 authored by hl's avatar hl

update

parent 0b3dc5bc
...@@ -4,7 +4,6 @@ import { NativeModules, Platform, NativeEventEmitter } from 'react-native'; ...@@ -4,7 +4,6 @@ import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
const { RNGeekImageEditor, ReactNativeSending } = NativeModules; const { RNGeekImageEditor, ReactNativeSending } = NativeModules;
function edit(json, callback) { function edit(json, callback) {
if (Platform.OS === 'android') {
let loadingManagerEmitter = new NativeEventEmitter(ReactNativeSending) let loadingManagerEmitter = new NativeEventEmitter(ReactNativeSending)
loadingManagerEmitter.addListener('ImgEditEvent', (data) => { loadingManagerEmitter.addListener('ImgEditEvent', (data) => {
console.log('data') console.log('data')
...@@ -12,7 +11,6 @@ function edit(json, callback) { ...@@ -12,7 +11,6 @@ function edit(json, callback) {
try { try {
if (data.result) { if (data.result) {
let backData = JSON.parse(data.result) let backData = JSON.parse(data.result)
// this._getNotice(backData)
callback(backData) callback(backData)
} }
} catch (err) { } catch (err) {
...@@ -21,9 +19,6 @@ function edit(json, callback) { ...@@ -21,9 +19,6 @@ function edit(json, callback) {
} }
}); });
RNGeekImageEditor.edit(json) RNGeekImageEditor.edit(json)
} else {
RNGeekImageEditor.edit(json, callback)
}
} }
export default RNGeekImageEditor; export default RNGeekImageEditor;
......
...@@ -16,9 +16,11 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -16,9 +16,11 @@ NS_ASSUME_NONNULL_BEGIN
@interface ImageEditorManger : NSObject @interface ImageEditorManger : NSObject
+ (instancetype) shared;
@property (nonatomic, readonly , copy) ImageEditedCallBack callback; @property (nonatomic, readonly , copy) ImageEditedCallBack callback;
- (void) showImages:(NSDictionary *)params cb:(ImageEditedCallBack)cb; - (void) showImages:(NSDictionary *)params;
@end @end
......
...@@ -21,13 +21,24 @@ ...@@ -21,13 +21,24 @@
@end @end
ImageEditorManger *manager = nil;
@implementation ImageEditorManger @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]; ImageEditorModel *model = [ImageEditorModel yy_modelWithJSON:params];
self.editModel = model; self.editModel = model;
[self showBrower:model]; [self showBrower:model];
_callback = cb;
} }
- (void) showBrower:(ImageEditorModel *)model { - (void) showBrower:(ImageEditorModel *)model {
...@@ -107,7 +118,7 @@ ...@@ -107,7 +118,7 @@
EditorImageModel *model =[self.editModel.images objectAtIndex:index]; EditorImageModel *model =[self.editModel.images objectAtIndex:index];
model.editedImage = [Utils saveImageTosandBox:photoEdit.editPreviewImage]; model.editedImage = [Utils saveImageTosandBox:photoEdit.editPreviewImage];
self.editModel.questions = [ImageEditorModel yy_modelWithJSON:photoEditingVC.data].questions; 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]; [photoEditingVC dismissViewControllerAnimated:true completion:nil];
} }
......
...@@ -17,15 +17,10 @@ ...@@ -17,15 +17,10 @@
RCT_EXPORT_MODULE(); RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(edit:(NSString *)json result:(RCTResponseSenderBlock)block) { RCT_EXPORT_METHOD(edit:(NSString *)json) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary *dic = [Utils dictionaryWithJsonString:json]; NSDictionary *dic = [Utils dictionaryWithJsonString:json];
[[[ImageEditorManger alloc] init] showImages:dic cb:^(ImageEditorModel * _Nullable editedParams) { [[[ImageEditorManger ] showImages:dic];
NSDictionary *result = [editedParams yy_modelToJSONObject];
if (block) {
block(@[result]);
}
}];
}); });
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
70AA071C2428964500913FEB /* Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 70AA071B2428964500913FEB /* Utils.m */; }; 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 */; }; 907D55EE8B15049A51D1C8F0 /* Pods_RNGeekImageEditor.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 64BE65D6A85DC61B6DBBD41A /* Pods_RNGeekImageEditor.framework */; };
DC88F9C3241A328F0074E2BD /* ImageEditorManger.m in Sources */ = {isa = PBXBuildFile; fileRef = DC88F9C0241A328E0074E2BD /* ImageEditorManger.m */; }; DC88F9C3241A328F0074E2BD /* ImageEditorManger.m in Sources */ = {isa = PBXBuildFile; fileRef = DC88F9C0241A328E0074E2BD /* ImageEditorManger.m */; };
DC88F9C4241A328F0074E2BD /* ImageEditorModel.m in Sources */ = {isa = PBXBuildFile; fileRef = DC88F9C1241A328E0074E2BD /* ImageEditorModel.m */; }; DC88F9C4241A328F0074E2BD /* ImageEditorModel.m in Sources */ = {isa = PBXBuildFile; fileRef = DC88F9C1241A328E0074E2BD /* ImageEditorModel.m */; };
...@@ -254,6 +255,8 @@ ...@@ -254,6 +255,8 @@
70AA07EA2428C82A00913FEB /* 错误-选中.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "错误-选中.png"; sourceTree = "<group>"; }; 70AA07EA2428C82A00913FEB /* 错误-选中.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "错误-选中.png"; sourceTree = "<group>"; };
70AA07EB2428C82A00913FEB /* 半对-选中.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>"; }; 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>"; }; 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>"; }; 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>"; }; DC88F9BF241A328E0074E2BD /* ImageEditorModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageEditorModel.h; sourceTree = "<group>"; };
...@@ -295,6 +298,8 @@ ...@@ -295,6 +298,8 @@
58B511D21A9E6C8500147676 = { 58B511D21A9E6C8500147676 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
70B1D2832428DCBB0019CC42 /* ReactNativeSending.h */,
70B1D2842428DCBB0019CC42 /* ReactNativeSending.m */,
DC88FCE2241A3D710074E2BD /* RNGeekImageEditor.h */, DC88FCE2241A3D710074E2BD /* RNGeekImageEditor.h */,
DC88FCE3241A3D710074E2BD /* RNGeekImageEditor.m */, DC88FCE3241A3D710074E2BD /* RNGeekImageEditor.m */,
DC88F9C2241A328F0074E2BD /* ImageEditorManger.h */, DC88F9C2241A328F0074E2BD /* ImageEditorManger.h */,
...@@ -1019,6 +1024,7 @@ ...@@ -1019,6 +1024,7 @@
DC88FCE4241A3D710074E2BD /* RNGeekImageEditor.m in Sources */, DC88FCE4241A3D710074E2BD /* RNGeekImageEditor.m in Sources */,
DC88F9C3241A328F0074E2BD /* ImageEditorManger.m in Sources */, DC88F9C3241A328F0074E2BD /* ImageEditorManger.m in Sources */,
DC88F9C4241A328F0074E2BD /* ImageEditorModel.m in Sources */, DC88F9C4241A328F0074E2BD /* ImageEditorModel.m in Sources */,
70B1D2852428DCBB0019CC42 /* ReactNativeSending.m in Sources */,
70AA071C2428964500913FEB /* Utils.m in Sources */, 70AA071C2428964500913FEB /* Utils.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; 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