Skip to content
This repository was archived by the owner on Dec 4, 2019. It is now read-only.

Commit 0390862

Browse files
committed
support for adding centerView to internal backstack
1 parent 78bb832 commit 0390862

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/com/tripvi/drawerlayout/Drawer.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import ti.modules.titanium.ui.WindowProxy;
1616
import android.support.v4.app.ActionBarDrawerToggle;
1717
import android.support.v4.app.FragmentManager;
18+
import android.support.v4.app.FragmentTransaction;
1819
import android.support.v4.widget.DrawerLayout;
1920
import android.support.v4.widget.DrawerLayout.LayoutParams;
2021
import android.support.v7.app.ActionBarActivity;
@@ -418,7 +419,7 @@ private void initRightDrawer() {
418419
/**
419420
* centerView 변경
420421
*/
421-
private void replaceCenterView(TiViewProxy viewProxy) {
422+
public void replaceCenterView(TiViewProxy viewProxy, boolean backstack) {
422423
if (viewProxy == this.centerView) {
423424
Log.d(TAG, "centerView was not changed");
424425
return;
@@ -440,14 +441,24 @@ private void replaceCenterView(TiViewProxy viewProxy) {
440441
// since only map uses TiUIFragment, here we check if view is a map,
441442
// then we add the fragment directly.
442443
if (contentView instanceof TiUIFragment) {
443-
fragmentManager.beginTransaction().replace(id_content_frame, ((TiUIFragment)contentView).getFragment())
444-
.commit();
444+
FragmentTransaction ft = fragmentManager.beginTransaction();
445+
ft.replace(id_content_frame, ((TiUIFragment)contentView).getFragment());
446+
if (backstack){
447+
Log.d(TAG, "adding Fragment to backstack");
448+
ft.addToBackStack(name);
449+
}
450+
ft.commit();
445451
} else {
446452
View view = contentView.getOuterView();
447453
ContentWrapperFragment fragment = new ContentWrapperFragment();
448454
fragment.setContentView(view);
449-
fragmentManager.beginTransaction().replace(id_content_frame, fragment)
450-
.commit();
455+
FragmentTransaction ft = fragmentManager.beginTransaction();
456+
ft.replace(id_content_frame, fragment);
457+
if (backstack){
458+
Log.d(TAG, "adding Fragment to backstack");
459+
ft.addToBackStack(name);
460+
}
461+
ft.commit();
451462
}
452463

453464
this.centerView = viewProxy;
@@ -497,7 +508,6 @@ public void processProperties(KrollDict d) {
497508
if (rightView instanceof WindowProxy)
498509
throw new IllegalStateException(
499510
"[ERROR] Cannot add window as a child view of other window");
500-
//
501511
this.rightView = (TiViewProxy) rightView;
502512
this.initRightDrawer();
503513
this.filter.addView(getNativeView(this.rightView));
@@ -511,8 +521,7 @@ public void processProperties(KrollDict d) {
511521
if (centerView instanceof WindowProxy)
512522
throw new IllegalStateException(
513523
"[ERROR] Cannot use window as a child view of other window");
514-
//
515-
replaceCenterView((TiViewProxy) centerView);
524+
replaceCenterView((TiViewProxy) centerView, false);
516525
} else {
517526
Log.e(TAG, "[ERROR] Invalid type for centerView");
518527
}
@@ -599,7 +608,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue,
599608
this.rightView = newProxy;
600609
} else if (key.equals(PROPERTY_CENTER_VIEW)) {
601610
TiViewProxy newProxy = (TiViewProxy) newValue;
602-
replaceCenterView(newProxy);
611+
replaceCenterView(newProxy, false);
603612
} else if (key.equals(PROPERTY_LEFT_VIEW_WIDTH)) {
604613
menuWidth = getDevicePixels(newValue);
605614

src/com/tripvi/drawerlayout/DrawerProxy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ public void setRightView(Object arg) {
222222
public void setCenterView(Object arg) {
223223
setPropertyAndFire(Drawer.PROPERTY_CENTER_VIEW, arg);
224224
}
225+
226+
@Kroll.method
227+
public void replaceCenterView(Object arg, boolean backstack) {
228+
drawer.replaceCenterView((TiViewProxy) arg, backstack);
229+
}
225230

226231
@Kroll.method
227232
@Kroll.setProperty

0 commit comments

Comments
 (0)