Skip to content

Commit

Permalink
[feature][PUSH-23593] inline In-Apps events for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Polshcha committed Jan 20, 2020
1 parent d783531 commit a1f2e13
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 14 deletions.
38 changes: 27 additions & 11 deletions InlineInApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class InlineInAppView extends React.Component {
// process raw event...
this.props.onLoaded(event.nativeEvent);
}

_onClosed = (event) => {
if (!this.props.onClosed) {
return;
Expand All @@ -19,6 +20,7 @@ class InlineInAppView extends React.Component {
// process raw event...
this.props.onClosed(event.nativeEvent);
}

_onSizeChanged = (event) => {
if (!this.props.onSizeChanged) {
return;
Expand All @@ -27,29 +29,43 @@ class InlineInAppView extends React.Component {
// process raw event...
this.props.onSizeChanged(event.nativeEvent);
}

render() {
return <InlineInAppView {...this.props} />;
return (
<PWInlineInAppView
{...this.props}
onLoaded = {this._onLoaded}
onClosed = {this._onClosed}
onSizeChanged = {this._onSizeChanged}
/>
);
}
}

InlineInAppView.propTypes = {
/**
* A Boolean value that determines whether the user may use pinch
* gestures to zoom in and out of the map.
* Value of the identifier property must be equal to the
* identifier attribute value of the in-app message you've
* created in Pushwoosh Control Panel
*/
identifier: PropTypes.string,
/**
* Callback that is called continuously when the user is dragging the map.
*/
* This event is called to notify you that an inline in-app
* was loaded and has been added to the view
*/
onLoaded: PropTypes.func,
/**
* Callback that is called continuously when the user is dragging the map.
*/
/**
* This event is called to notify you that an inline in-app
* view has been closed by the user
*/
onClosed: PropTypes.func,
/**
* Callback that is called continuously when the user is dragging the map.
*/
* This event is called to notify you that an inline in-app
* view size has been changed
*/
onSizeChanged: PropTypes.func,
};

module.exports = requireNativeComponent('PWInlineInAppView', InlineInAppView);
var PWInlineInAppView = requireNativeComponent('PWInlineInAppView', InlineInAppView)

export default InlineInAppView
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.pushwoosh.reactnativeplugin;

import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;

import java.util.Map;

public class InlineInAppManager extends SimpleViewManager<RCTInlineInAppView> {
public static final String REACT_CLASS = "PWInlineInAppView";

Expand All @@ -14,12 +17,32 @@ public String getName() {

@Override
public RCTInlineInAppView createViewInstance(ThemedReactContext context) {
return new RCTInlineInAppView(context);
RCTInlineInAppView view = new RCTInlineInAppView(context);
return view;
}


@ReactProp(name = "identifier")
public void setIdentifier(final RCTInlineInAppView view, String identifier) {
view.setIdentifier(identifier);
}

public Map getExportedCustomBubblingEventTypeConstants() {
return MapBuilder.builder()
.put(
"onLoaded",
MapBuilder.of(
"phasedRegistrationNames",
MapBuilder.of("bubbled", "onLoaded")))
.put(
"onClosed",
MapBuilder.of(
"phasedRegistrationNames",
MapBuilder.of("bubbled", "onClosed")))
.put(
"onSizeChanged",
MapBuilder.of(
"phasedRegistrationNames",
MapBuilder.of("bubbled", "onSizeChanged")))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@

import androidx.annotation.NonNull;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.pushwoosh.inapp.view.inline.InlineInAppView;
import com.pushwoosh.inapp.view.inline.InlineInAppViewListener;

public class RCTInlineInAppView extends InlineInAppView {
public class RCTInlineInAppView extends InlineInAppView implements InlineInAppViewListener {
public RCTInlineInAppView(@NonNull Context context) {
super(context);
this.addInlineInAppViewListener(this);
setupLayoutHack();
}

Expand All @@ -23,6 +29,7 @@ public void doFrame(long frameTimeNanos) {
Choreographer.getInstance().postFrameCallback(this);
}
});

}

void manuallyLayoutChildren() {
Expand All @@ -33,4 +40,38 @@ void manuallyLayoutChildren() {
child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());
}
}

@Override
public void onInlineInAppLoaded() {
WritableMap event = Arguments.createMap();
event.putString("identifier", this.getIdentifier());
ReactContext reactContext = (ReactContext)getContext();
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
getId(),
"onLoaded",
event);
}

@Override
public void onInlineInAppViewClosed() {
WritableMap event = Arguments.createMap();
event.putString("identifier", this.getIdentifier());
ReactContext reactContext = (ReactContext)getContext();
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
getId(),
"onClosed",
event);
}

@Override
public void onInlineInAppViewChangedSize(int var1, int var2) {
WritableMap event = Arguments.createMap();
event.putString("width", String.valueOf(var1));
event.putString("height", String.valueOf(var2));
ReactContext reactContext = (ReactContext)getContext();
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
getId(),
"onSizeChanged",
event);
}
}

0 comments on commit a1f2e13

Please sign in to comment.