Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
Add nav onSupportNavigateUp event (#2542)
Browse files Browse the repository at this point in the history
add BackPressed listener
  • Loading branch information
Darin726 authored and YorkShen committed Jun 13, 2019
1 parent 84288a8 commit c22ff1a
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan

private List<String> mLayerOverFlowListeners;

private List<ActionBarHandler> mWXActionbarHandlers;

private List<OnBackPressedHandler> mWXBackPressedHandlers;

private WXSDKInstance mParentInstance;

/**
Expand Down Expand Up @@ -274,6 +278,19 @@ public void setCustomFontNetworkHandler(CustomFontNetworkHandler customFontNetwo
this.mCustomFontNetworkHandler = customFontNetworkHandler;
}


/**
* ActionBar Handler
*/

public interface ActionBarHandler {
boolean onSupportNavigateUp();
}

public interface OnBackPressedHandler {
boolean onBackPressed();
}

/**
* set make weexCore run in single process mode
* @param flag true means weexCore run in single process mode or multi process mode
Expand Down Expand Up @@ -1359,7 +1376,26 @@ public boolean onActivityBack() {
return false;
}

public boolean onSupportNavigateUp() {
if (mWXActionbarHandlers != null) {
for (ActionBarHandler handler : mWXActionbarHandlers) {
if (handler.onSupportNavigateUp()) {
return true;
}
}
}
return false;
}

public boolean onBackPressed() {
if(mWXBackPressedHandlers != null) {
for (OnBackPressedHandler handler : mWXBackPressedHandlers) {
if(handler.onBackPressed()) {
return true;
}
}
}

WXComponent comp = getRootComponent();
if(comp != null) {
WXEvent events= comp.getEvents();
Expand Down Expand Up @@ -1712,6 +1748,8 @@ public synchronized void destroy() {
mFlatGUIContext = null;
mInstanceOnFireEventInterceptorList = null;
mWXScrollListeners = null;
mWXActionbarHandlers = null;
mWXBackPressedHandlers = null;
mRenderContainer = null;
mNestedInstanceInterceptor = null;
mUserTrackAdapter = null;
Expand Down Expand Up @@ -1845,6 +1883,41 @@ public synchronized void registerOnWXScrollListener(OnWXScrollListener wxScrollL
mWXScrollListeners.add(wxScrollListener);
}

public synchronized void registerActionbarHandler(ActionBarHandler actionBarHandler) {
if(actionBarHandler == null) {
return;
}
if(mWXActionbarHandlers == null) {
mWXActionbarHandlers = new ArrayList<>();
}

mWXActionbarHandlers.add(actionBarHandler);
}

public synchronized void unRegisterActionbarHandler(ActionBarHandler actionBarHandler) {
if(mWXActionbarHandlers != null && actionBarHandler != null) {
mWXActionbarHandlers.remove(actionBarHandler);
}
}

public synchronized void registerBackPressedHandler(OnBackPressedHandler backPressedHandler) {
if(backPressedHandler == null) {
return;
}

if(mWXBackPressedHandlers == null) {
mWXBackPressedHandlers = new ArrayList<>();
}

mWXBackPressedHandlers.add(backPressedHandler);
}

public synchronized void unRegisterBackPressedHandler(OnBackPressedHandler backPressedHandler) {
if(mWXBackPressedHandlers != null && backPressedHandler != null) {
mWXBackPressedHandlers.remove(backPressedHandler);
}
}

static int sScreenHeight = -1;
public void setSize(int width, int height) {
if (width > 0 && height > 0 & !isDestroy && mRendered && mRenderContainer != null) {
Expand Down

0 comments on commit c22ff1a

Please sign in to comment.