Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix topBar title with subtitle view #6509

Merged
merged 5 commits into from
Sep 1, 2020
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
6 changes: 6 additions & 0 deletions e2e/Stack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ describe('Stack', () => {
await expect(elementByLabel('back button clicked')).toBeVisible();
});

it('push title with subtitle', async () => {
await elementById(TestIDs.PUSH_TITLE_WITH_SUBTITLE).tap();
await expect(elementByLabel('Title')).toBeVisible();
await expect(elementByLabel('Subtitle')).toBeVisible();
});

it('screen lifecycle', async () => {
await elementById(TestIDs.PUSH_LIFECYCLE_BTN).tap();
await expect(elementByLabel('didAppear')).toBeVisible();
Expand Down
4 changes: 3 additions & 1 deletion lib/ios/RNNComponentPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ - (void)applyOptions:(RNNNavigationOptions *)options {
}
[viewController setSearchBarWithPlaceholder:[withDefault.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar:hideNavBarOnFocusSearchBar];
}

[_topBarTitlePresenter applyOptions:withDefault.topBar];
}

- (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
Expand All @@ -70,7 +72,7 @@ - (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
RNNComponentViewController* viewController = self.boundViewController;
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];

[_topBarTitlePresenter applyOptionsOnInit:withDefault.topBar];
[_topBarTitlePresenter applyOptionsOnInit:withDefault.topBar];

[viewController setTopBarPrefersLargeTitle:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
[viewController setDrawBehindTopBar:[withDefault.topBar shouldDrawBehind]];
Expand Down
2 changes: 2 additions & 0 deletions lib/ios/TopBarTitlePresenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- (void)applyOptionsOnInit:(RNNTopBarOptions *)options;

- (void)applyOptions:(RNNTopBarOptions *)options;

- (void)mergeOptions:(RNNTopBarOptions *)options resolvedOptions:(RNNTopBarOptions *)resolvedOptions;

- (void)setCustomNavigationTitleView:(RNNTopBarOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock;
Expand Down
36 changes: 18 additions & 18 deletions lib/ios/TopBarTitlePresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ @implementation TopBarTitlePresenter {
}

- (void)applyOptionsOnInit:(RNNTopBarOptions *)initialOptions {
[self updateTitleWithOptions:initialOptions];
if (initialOptions.title.component.hasValue) {
[self setCustomNavigationTitleView:initialOptions perform:nil];
} else if (initialOptions.title.text.hasValue) {
[self removeTitleComponents];
self.boundViewController.navigationItem.title = initialOptions.title.text.get;
}
}

- (void)updateTitleWithOptions:(RNNTopBarOptions *)options {
if (options.title.component.hasValue) {
[self setCustomNavigationTitleView:options perform:nil];
} else if (options.subtitle.text.hasValue) {
- (void)applyOptions:(RNNTopBarOptions *)options {
if (options.subtitle.text.hasValue) {
[self setTitleViewWithSubtitle:options];
} else if (options.title.text.hasValue) {
[self removeTitleComponents];
self.boundViewController.navigationItem.title = options.title.text.get;
}
}

Expand All @@ -35,18 +35,18 @@ - (void)mergeOptions:(RNNTopBarOptions *)options resolvedOptions:(RNNTopBarOptio
}

- (void)setTitleViewWithSubtitle:(RNNTopBarOptions *)options {
if (!_customTitleView && ![options.largeTitle.visible getWithDefaultValue:NO]) {
_titleViewHelper = [[RNNTitleViewHelper alloc] initWithTitleViewOptions:options.title subTitleOptions:options.subtitle viewController:self.boundViewController];
if (!_customTitleView && ![options.largeTitle.visible getWithDefaultValue:NO]) {
_titleViewHelper = [[RNNTitleViewHelper alloc] initWithTitleViewOptions:options.title subTitleOptions:options.subtitle viewController:self.boundViewController];

if (options.title.text.hasValue) {
[_titleViewHelper setTitleOptions:options.title];
}
if (options.subtitle.text.hasValue) {
[_titleViewHelper setSubtitleOptions:options.subtitle];
}
if (options.title.text.hasValue) {
[_titleViewHelper setTitleOptions:options.title];
}
if (options.subtitle.text.hasValue) {
[_titleViewHelper setSubtitleOptions:options.subtitle];
}

[_titleViewHelper setup];
}
[_titleViewHelper setup];
}
}

- (void)renderComponents:(RNNTopBarOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
Expand Down
23 changes: 23 additions & 0 deletions playground/src/screens/StackScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
PUSH_LIFECYCLE_BTN,
POP_NONE_EXISTENT_SCREEN_BTN,
PUSH_CUSTOM_BACK_BTN,
PUSH_TITLE_WITH_SUBTITLE,
PUSH_LAZY_BTN,
CUSTOM_BACK_BTN,
SEARCH_BTN,
Expand Down Expand Up @@ -57,6 +58,11 @@ export default class StackScreen extends React.Component<NavigationComponentProp
testID={PUSH_CUSTOM_BACK_BTN}
onPress={this.pushCustomBackButton}
/>
<Button
label="Push Title With Subtitle"
testID={PUSH_TITLE_WITH_SUBTITLE}
onPress={this.pushTitleWithSubtitle}
/>
<Button label="Set Stack Root" testID={SET_STACK_ROOT_BTN} onPress={this.setStackRoot} />
<Button
label="Set Stack Root With ID"
Expand Down Expand Up @@ -99,6 +105,23 @@ export default class StackScreen extends React.Component<NavigationComponentProp
},
});

pushTitleWithSubtitle = () =>
Navigation.push(this, {
component: {
name: Screens.Pushed,
options: {
topBar: {
title: {
text: 'Title',
},
subtitle: {
text: 'Subtitle',
},
},
},
},
});

search = () => Navigation.push(this, Screens.Search);

setStackRoot = () =>
Expand Down
1 change: 1 addition & 0 deletions playground/src/testIDs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const testIDs = {
TOP_BAR_BTN: 'TOP_BAR_BUTTON',
CUSTOM_BACK_BTN: 'CUSTOM_BACK_BUTTON',
PUSH_CUSTOM_BACK_BTN: 'PUSH_CUSTOM_BACK_BTN',
PUSH_TITLE_WITH_SUBTITLE: 'PUSH_TITLE_WITH_SUBTITLE',
BACK_BUTTON: 'BACK_BUTTON',
SWITCH_TAB_BY_INDEX_BTN: 'SWITCH_TAB_BY_INDEX_BTN',
SWITCH_TAB_BY_COMPONENT_ID_BTN: 'SWITCH_TAB_BY_COMPONENT_ID_BTN',
Expand Down