forked from emartech/react-native-emarsys-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove unnecessary logging MV-332
- Loading branch information
1 parent
2834e26
commit f3793af
Showing
10 changed files
with
212 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
android/src/main/java/com/emarsys/rnwrapper/RNEmarsysInlineInAppViewManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.emarsys.rnwrapper; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.emarsys.inapp.ui.InlineInAppView; | ||
import com.facebook.react.bridge.Arguments; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReadableArray; | ||
import com.facebook.react.bridge.WritableMap; | ||
import com.facebook.react.common.MapBuilder; | ||
import com.facebook.react.uimanager.SimpleViewManager; | ||
import com.facebook.react.uimanager.ThemedReactContext; | ||
import com.facebook.react.uimanager.events.RCTEventEmitter; | ||
|
||
import java.util.Map; | ||
|
||
public class RNEmarsysInlineInAppViewManager extends SimpleViewManager<InlineInAppView> { | ||
|
||
private static final String TAG = "RNEmarsysInlineInAppView"; | ||
private final int COMMAND_LOAD_IN_APP = 1; | ||
|
||
private final ReactApplicationContext reactContext; | ||
|
||
public RNEmarsysInlineInAppViewManager(ReactApplicationContext reactContext) { | ||
this.reactContext = reactContext; | ||
} | ||
|
||
@Override | ||
public String getName() { return TAG; } | ||
|
||
@Override | ||
public InlineInAppView createViewInstance(ThemedReactContext context) { | ||
InlineInAppView view = new InlineInAppView(reactContext); | ||
view.setOnAppEventListener((property, json) -> { | ||
WritableMap event = Arguments.createMap(); | ||
event.putString("eventName", property); | ||
event.putMap("payload", MapUtil.jsonToWritableMap(json).getMap("payload")); | ||
reactContext.getJSModule(RCTEventEmitter.class) | ||
.receiveEvent(view.getId(), "onAppEvent", event); | ||
return null; | ||
}); | ||
view.setOnCompletionListener((error) -> { | ||
WritableMap event = Arguments.createMap(); | ||
event.putString("error", error == null ? null : error.getLocalizedMessage()); | ||
reactContext.getJSModule(RCTEventEmitter.class) | ||
.receiveEvent(view.getId(), "onCompleted", event); | ||
}); | ||
view.setOnCloseListener(() -> { | ||
reactContext.getJSModule(RCTEventEmitter.class) | ||
.receiveEvent(view.getId(), "onClose", null); | ||
return null; | ||
}); | ||
return view; | ||
} | ||
|
||
public Map getExportedCustomBubblingEventTypeConstants() { | ||
return MapBuilder.builder().put( | ||
"onAppEvent", | ||
MapBuilder.of( | ||
"phasedRegistrationNames", | ||
MapBuilder.of("bubbled", "onAppEvent") | ||
) | ||
).put( | ||
"onCompleted", | ||
MapBuilder.of( | ||
"phasedRegistrationNames", | ||
MapBuilder.of("bubbled", "onCompleted") | ||
) | ||
).put( | ||
"onClose", | ||
MapBuilder.of( | ||
"phasedRegistrationNames", | ||
MapBuilder.of("bubbled", "onClose") | ||
) | ||
).build(); | ||
} | ||
|
||
@Override | ||
public Map<String, Integer> getCommandsMap() { | ||
return MapBuilder.of("loadInApp", COMMAND_LOAD_IN_APP); | ||
} | ||
|
||
@Override | ||
public void receiveCommand( | ||
@NonNull InlineInAppView root, | ||
String commandId, | ||
@Nullable ReadableArray args | ||
) { | ||
super.receiveCommand(root, commandId, args); | ||
|
||
int commandIdInt = Integer.parseInt(commandId); | ||
switch (commandIdInt) { | ||
case COMMAND_LOAD_IN_APP: | ||
String viewId = args.getString(0); | ||
root.loadInApp(viewId); | ||
break; | ||
default: { } | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#import <React/RCTViewManager.h> | ||
#import <React/RCTUIManager.h> | ||
|
||
#import "EMSInlineInAppView.h" | ||
|
||
@interface RNEmarsysInlineInAppView: EMSInlineInAppView | ||
|
||
@property (nonatomic, copy) RCTBubblingEventBlock onAppEvent; | ||
@property (nonatomic, copy) RCTBubblingEventBlock onCompleted; | ||
@property (nonatomic, copy) RCTBubblingEventBlock onClose; | ||
|
||
@end | ||
|
||
|
||
@interface RNEmarsysInlineInAppViewManager : RCTViewManager | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#import "RNEmarsysInlineInAppViewManager.h" | ||
|
||
@implementation RNEmarsysInlineInAppView | ||
|
||
@end | ||
|
||
|
||
@implementation RNEmarsysInlineInAppViewManager | ||
|
||
RCT_EXPORT_MODULE() | ||
|
||
- (UIView *)view { | ||
RNEmarsysInlineInAppView *view = [[RNEmarsysInlineInAppView alloc] init]; | ||
__weak RNEmarsysInlineInAppView *weakView = view; | ||
view.eventHandler = ^(NSString *eventName, NSDictionary<NSString *, NSObject *> *payload) { | ||
if (!weakView.onAppEvent) { return; } | ||
weakView.onAppEvent(@{ @"eventName": eventName, @"payload": payload }); | ||
}; | ||
view.completionBlock = ^(NSError *error) { | ||
if (!weakView.onCompleted) { return; } | ||
weakView.onCompleted(@{ @"error": error ? error.localizedDescription : [NSNull null] }); | ||
}; | ||
view.closeBlock = ^ { | ||
if (!weakView.onClose) { return; } | ||
weakView.onClose(@{ }); | ||
}; | ||
return view; | ||
} | ||
|
||
RCT_EXPORT_VIEW_PROPERTY(onAppEvent, RCTBubblingEventBlock) | ||
RCT_EXPORT_VIEW_PROPERTY(onCompleted, RCTBubblingEventBlock) | ||
RCT_EXPORT_VIEW_PROPERTY(onClose, RCTBubblingEventBlock) | ||
|
||
RCT_EXPORT_METHOD(loadInApp:(NSNumber * _Nonnull)viewTag withViewId:(NSString * _Nonnull)viewId) { | ||
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) { | ||
UIView *view = viewRegistry[viewTag]; | ||
if (!view || ![view isKindOfClass:[EMSInlineInAppView class]]) { return; } | ||
[(EMSInlineInAppView *)view loadInAppWithViewId:viewId]; | ||
}]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters