Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ private void setupPages(ArrayList<Screen> screens) {

private void setupToolbar(ArrayList<Screen> screens) {
Screen initialScreen = screens.get(0);
setNavigationStyle(initialScreen);
mToolbar.setScreens(screens);
mToolbar.setTitle(initialScreen.title);
setSupportActionBar(mToolbar);
mToolbar.updateToolbar(initialScreen);
setNavigationStyle(initialScreen);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still sets window styles so I left it there even though there's now a slight duplication. Lets look at that in another PR?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we'll address that in a separate PR. I'll merge soon. Thanks for the contribution Matt 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome! Great library, it's making a huge difference to some of my apps compared to the official nav. I'll keep jumping in where I can to fill gaps.

}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This had to be at the bottom to ensure the action bar was set before applying styles (else you can't show/hide).


@Override
Expand Down Expand Up @@ -104,14 +103,15 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public void push(Screen screen) {
super.push(screen);
setNavigationStyle(screen);
mScreenStacks.get(mCurrentStackPosition).push(screen);
}

@Override
public Screen pop(String navigatorId) {
super.pop(navigatorId);
Screen screen = mScreenStacks.get(mCurrentStackPosition).pop();
setNavigationStyle(screen);
setNavigationStyle(getCurrentScreen());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When popping it was applying the style of the screen that had just been popped rather than the new screen.

return screen;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ protected void handleOnCreate() {
}

protected void setupToolbar(Screen screen) {
mToolbar.updateToolbar(screen);
setNavigationStyle(screen);
mToolbar.setTitle(screen.title);
setSupportActionBar(mToolbar);
}

@Override
Expand All @@ -52,7 +51,7 @@ public void push(Screen screen) {
public Screen pop(String navigatorId) {
super.pop(navigatorId);
Screen screen = mScreenStack.pop();
setNavigationStyle(screen);
setNavigationStyle(getCurrentScreen());
return screen;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ protected void handleOnCreate() {

private void setupToolbar(ArrayList<Screen> screens) {
Screen initialScreen = screens.get(0);
setNavigationStyle(initialScreen);
mToolbar.setScreens(screens);
mToolbar.setTitle(initialScreen.title);
mToolbar.setupToolbarButtonsAsync(initialScreen);
setSupportActionBar(mToolbar);
mToolbar.updateToolbar(initialScreen);
setNavigationStyle(initialScreen);
}

@Override
Expand All @@ -70,14 +68,15 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public void push(Screen screen) {
super.push(screen);
setNavigationStyle(screen);
mAdapter.push(screen);
}

@Override
public Screen pop(String navigatorId) {
super.pop(navigatorId);
Screen screen = mAdapter.pop(navigatorId);
setNavigationStyle(screen);
setNavigationStyle(getCurrentScreen());
return screen;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ protected ReadableMap getMap(ReadableMap map, String key) {
protected Integer getColor(ReadableMap map, String key) {
return map.hasKey(key) ? Color.parseColor(map.getString(key)) : null;
}

protected Boolean getBoolean(ReadableMap map, String key) {
return map.hasKey(key) ? map.getBoolean(key) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class Screen extends JsonObject implements Serializable {
private static final String KEY_TOOL_BAR_STYLE = "navigatorStyle";
private static final String KEY_STATUS_BAR_COLOR = "statusBarColor";
private static final String KEY_TOOL_BAR_COLOR = "toolBarColor";
private static final String KEY_TOOL_BAR_HIDDEN = "navBarHidden";
private static final String KEY_NAVIGATION_BAR_COLOR = "navigationBarColor";
private static final String KEY_BUTTONS_TINT_COLOR = "buttonsTint";
private static final String KEY_TITLE_COLOR = "titleColor";
Expand All @@ -54,6 +55,7 @@ public class Screen extends JsonObject implements Serializable {

// Navigation styling
@Nullable @ColorInt public Integer toolBarColor;
@Nullable public Boolean toolBarHidden;
@Nullable @ColorInt public Integer statusBarColor;
@Nullable @ColorInt public Integer navigationBarColor;
@Nullable @ColorInt public Integer buttonsTintColor;
Expand Down Expand Up @@ -105,6 +107,7 @@ public void setToolbarStyle(ReadableMap screen) {
ReadableMap style = getMap(screen, KEY_TOOL_BAR_STYLE);
if (style != null) {
toolBarColor = getColor(style, KEY_TOOL_BAR_COLOR);
toolBarHidden = getBoolean(style, KEY_TOOL_BAR_HIDDEN);
statusBarColor = getColor(style, KEY_STATUS_BAR_COLOR);
navigationBarColor = getColor(style, KEY_NAVIGATION_BAR_COLOR);
buttonsTintColor = getColor(style, KEY_BUTTONS_TINT_COLOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class RnnModal extends Dialog implements DialogInterface.OnDismissListene
private ScreenStack mScreenStack;
private View mContentView;
private Screen mScreen;
private RnnToolBar mToolBar;

public RnnModal(BaseReactActivity context, Screen screen) {
super(context, R.style.Modal);
Expand All @@ -41,13 +42,10 @@ public RnnModal(BaseReactActivity context, Screen screen) {
private void init(final Context context) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
mContentView = LayoutInflater.from(context).inflate(R.layout.modal_layout, null, false);
RnnToolBar toolBar = (RnnToolBar) mContentView.findViewById(R.id.toolbar);
mToolBar = (RnnToolBar) mContentView.findViewById(R.id.toolbar);
mScreenStack = (ScreenStack) mContentView.findViewById(R.id.screenStack);

setContentView(mContentView);
toolBar.setStyle(mScreen);
toolBar.setTitle(mScreen.title);
toolBar.setupToolbarButtonsAsync(mScreen);
mToolBar.updateToolbar(mScreen);
mScreenStack.push(mScreen, new RctView.OnDisplayedListener() {
@Override
public void onDisplayed() {
Expand All @@ -67,10 +65,17 @@ public void onDisplayed() {

public void push(Screen screen) {
mScreenStack.push(screen);
mToolBar.updateToolbar(mScreen);
}

public Screen pop() {
return mScreenStack.pop();
if (mScreenStack.getStackSize() > 1) {
return mScreenStack.pop();
} else {
ModalController.getInstance().remove();
super.onBackPressed();
return null;
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When pop was called on the only remaining screen on a modal it didn't appear to be clearing the modal out properly.

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.support.annotation.UiThread;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.view.Menu;
Expand Down Expand Up @@ -70,6 +72,12 @@ public void setStyle(Screen screen) {
} else {
resetTitleTextColor();
}

if (screen.toolBarHidden != null && screen.toolBarHidden) {
hideToolbar();
} else {
showToolbar();
}
}

private void resetBackground() {
Expand All @@ -95,6 +103,20 @@ public void setupToolbarButtonsAsync(Screen oldScreen, Screen newScreen) {
}
}

private void showToolbar() {
ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();
if (actionBar != null) {
actionBar.show();
}
}

private void hideToolbar() {
ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
}

@SuppressWarnings({"ConstantConditions"})
public void showBackButton(Screen screen) {
ActionBar actionBar = ContextProvider.getActivityContext().getSupportActionBar();
Expand Down Expand Up @@ -126,6 +148,18 @@ public void hideBackButton() {
ContextProvider.getActivityContext().getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}

@UiThread
public void updateToolbar(Screen screen) {
setSupportActionBar();
setTitle(screen.title);
setStyle(screen);
setupToolbarButtonsAsync(screen);
}

private void setSupportActionBar() {
((AppCompatActivity) getContext()).setSupportActionBar(this);
}

private static class SetupToolbarButtonsTask extends AsyncTask<Void, Void, Map<String, Drawable>> {
private final List<Button> mOldButtons;
private final List<Button> mNewButtons;
Expand Down