Skip to content

Add support for hiding the Toolbar on Android#52

Merged
guyca merged 1 commit into
wix:masterfrom
MattDavies:master
Jun 4, 2016
Merged

Add support for hiding the Toolbar on Android#52
guyca merged 1 commit into
wix:masterfrom
MattDavies:master

Conversation

@MattDavies
Copy link
Copy Markdown
Contributor

This PR will ideally also make it a lot easier to support multiple Toolbar styles within a single app.

Most of the edge cases I could find were around multiple modals, but worth checking tab/single screen activity push/pop shows/hides the Toolbar correctly as well.

Haven't touched native Android code before, so really open to feedback and suggestions.

@guyca
Copy link
Copy Markdown
Collaborator

guyca commented Jun 3, 2016

@MattDavies Thanks a lot for the PR. I'm sure the community will appreciate it!

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 = "toolBarHidden";
Copy link
Copy Markdown
Collaborator

@guyca guyca Jun 3, 2016

Choose a reason for hiding this comment

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

Lets change the text toolBarHidden to navBarHidden which is the property we already use in iOS

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.

Sure, easy. There are a few other "toolBar" props we can update in a separate PR too.

@MattDavies
Copy link
Copy Markdown
Contributor Author

@guyca Changed to navBarHidden

mContext.runOnUiThread(new Runnable() {
@Override
public void run() {
updateToolbar(mOriginalScreen, mOriginalToolbar);
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.

If the Modal is dismissed, the previous toolbar already has the correct style and buttons. Do we call updateToolbar only for mContext.setSupportActionBar(toolbar); ?

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.

Ah. I was finding the visibility of the previous toolbar was being altered and I needed to reset it, but that might have been before I was setting the action toolbar context correctly on the modal. Let me have a play and see if I can clean this up.

Copy link
Copy Markdown
Collaborator

@guyca guyca Jun 4, 2016

Choose a reason for hiding this comment

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

Great. What do you think about moving updateToolbar to RnnToolbar class? I didn't have time to check this, but I think it will be used from other places as well.

Maybe something like this:

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

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

Then, in RnnModal we would call mToolBar.updateToolbar(mScreen);
This also eliminates the need to keep a hard ref to mOriginalToolbar, a View that belongs to the previous Activity/Modal, which is a bad practice.

If we expose setSupportActionBar we also don't need to keep a ref to mOriginalScreen - seems like it simplifies the class a bit.

@MattDavies MattDavies force-pushed the master branch 2 times, most recently from 3708dd9 to ad56faf Compare June 4, 2016 11:55
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.

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.

@MattDavies
Copy link
Copy Markdown
Contributor Author

Hey @guyca I managed to simplify the modal logic a fair bit and fixed another couple of issues which I was hitting. I've got a couple of changes in https://github.com/MattDavies/react-native-navigation/tree/test-toolbar-hide which you might find useful for testing as well.

@MattDavies MattDavies force-pushed the master branch 2 times, most recently from f0eafd9 to 1498ad8 Compare June 4, 2016 12:07
}

public void push(Screen screen) {
updateToolbar(screen, mToolBar);
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.

It didn't look as though we were previously updating the toolbar style for a pushed screen within a modal.

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.

Good catch! We also miss this when pushing a screen in Activities (BottomTabActivity and SingleScreenActivity). That's why I suggested we declare updateToolbar in RnnToolbar.

@guyca
Copy link
Copy Markdown
Collaborator

guyca commented Jun 4, 2016

@MattDavies I went over #60ab611a31a5b5681e236b4f7a8ca3f0a51f6622 and seems like you're still using toolBarHidden instead of navBarHidden. Or did I miss something?

If you wish I can move updateToolbar to RnnToolBar for you. Ping me once you update the PR and I'll merge it.

PS
I'll be out of the office all of next week, So if we don't merge today I'll ask one of the other guys here to pick this up.

@MattDavies
Copy link
Copy Markdown
Contributor Author

MattDavies commented Jun 4, 2016

@guyca Updated to move updateToolbar to RnnToolbar. It definitely reads a lot clearer now - great suggestion!

I think I lost the navBarHidden change somewhere along the lines...added it back.

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.

@guyca guyca merged commit 75114aa into wix:master Jun 4, 2016
guyca added a commit that referenced this pull request Jun 4, 2016
Minor refactor after merging #52.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants