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

Added back button for nav bar #141

Closed

Conversation

stefanrenne
Copy link

@stefanrenne stefanrenne commented Nov 4, 2020

What's in this PR?

Replace this text with information about what's in your PR. What's changed? Why has it changed? Reference any GitHub issue this PR relates to, etc.

  • Added back button in nav bar

Pre-merge checklist

Before merging any PR, please check the following common things that should be done beforehand. These aren't all always required, so just check the box if it doesn't apply.

  • When adding files, make sure they're added to the right target. If you're adding new files that should be bundled up with Cocoapods etc, they need to be added to the TABTestKit target, not Pods-TABTestKit_Example etc.
  • Run pod install to ensure that the latest changes are in the Example project. Without this, Carthage might not see the latest changes.
  • Added and updated tests where possible. This isn't always possible but try wherever you can. The example app contains UI tests to test many of the TABTestKit features.
  • Updated the CHANGELOG. For any changes pending a release, add to the Pending section. For releases, move everything pending to the release section.
  • Updated the README. Add info for any new features, update existing info for anything that's changed or needs extra info.

@stefanrenne
Copy link
Author

A different solution would be to add a custom Element, don't know what would be preferred?

Example:

struct BackBarButton: Element, Tappable {
    let id: String? = nil
    let index: Int = 0
    let parent: Element = NavBar()
    let type: XCUIElement.ElementType = .button
}

@KaneCheshire
Copy link
Contributor

A different solution would be to add a custom Element, don't know what would be preferred?

Example:

struct BackBarButton: Element, Tappable {
    let id: String? = nil
    let index: Int = 0
    let parent: Element = NavBar()
    let type: XCUIElement.ElementType = .button
}

I personally prefer this because it means you're still enforcing that all buttons should have some sort of ID, unlike if you allow nil as the id (which I hope helps with accessibility in the app because people will have to assign an accessibility label or identifier)

@KaneCheshire
Copy link
Contributor

Don't most back buttons have a specific title or label? Either "Back" or the title of the previous screen? This could maybe be solved with an extension or update on NavBar:

extension NavBar {

  func backButton(titled title: String = "Back") -> Button {
    return Button(id: title, parent: self)
  }
}

@stefanrenne
Copy link
Author

stefanrenne commented Nov 4, 2020

Don't most back buttons have a specific title or label? Either "Back" or the title of the previous screen? This could maybe be solved with an extension or update on NavBar:

extension NavBar {

  func backButton(titled title: String = "Back") -> Button {
    return Button(id: title, parent: self)
  }
}

By default the back item has the title of the previous screen, would be nice to make it more foolproof

print(navigationController!.navigationBar.backItem!)
// output: <UINavigationItem: 0x7ff8fb006180> title='sdgsdfgdf'

@KaneCheshire
Copy link
Contributor

Don't most back buttons have a specific title or label? Either "Back" or the title of the previous screen? This could maybe be solved with an extension or update on NavBar:

extension NavBar {

  func backButton(titled title: String = "Back") -> Button {
    return Button(id: title, parent: self)
  }
}

By default the back item has the title of the previous screen, so I guess that won't work

print(navigationController!.navigationBar.backItem!)
// output: <UINavigationItem: 0x7ff8fb006180> title='sdgsdfgdf'

Yeah that's what I said 😬 in your tests you'd have to know what the previous screen was so you can tap the back button, but since you're in control of your tests that shouldn't be a problem?

Given(I: tap(navBar.backButton(titled: "sdgsdfgdf")))

@stefanrenne
Copy link
Author

stefanrenne commented Nov 4, 2020

I have to check in our real project, because we are doing some magic to hide the title in the navigationbar.
Also the default "Back" could be language specific.
In our project the title seems to be empty

po navigationController?.navigationBar.backItem?.backBarButtonItem
▿ Optional<UIBarButtonItem>
  - some : <UIBarButtonItem: 0x7fa3ffc5d8c0> menuOnTouchDown menu=0x6000013bad50 title=''

@KaneCheshire
Copy link
Contributor

I have to check in our real project, because we are doing some magic to hide the title in the navigationbar.
Also the default "Back" could be language specific.
In our project the title seems to be empty

po navigationController?.navigationBar.backItem?.backBarButtonItem
▿ Optional<UIBarButtonItem>
  - some : <UIBarButtonItem: 0x7fa3ffc5d8c0> menuOnTouchDown menu=0x6000013bad50 title=''

You could just remove the default, it was there as a suggestion :)

I'm guessing the title is "" because you've removed the title and just have an arrow? What happens for VoiceOver when it navigates over that, I assume it just reads out "Back"? It might be worth putting a breakpoint in your tests when the button is visible and then printing out the hierarchy so you can see what the tests can see:

po App.shared or po NavBar()

Alternatively you might be able to just use the Accessibility Inspector. As a last resort you could add a custom accessibilityIdentifier to the back button wherever you're removing the title?

@stefanrenne
Copy link
Author

stefanrenne commented Nov 4, 2020

Yeah there you go, "Vorige" is Dutch for "Previous"

NavigationBar, 0x60000309a4c0, {{0.0, 58.0}, {414.0, 56.0}}, identifier: 'LargeTitleView'
   Button, 0x60000309a5a0, {{0.0, 64.0}, {44.0, 44.0}}, label: 'Vorige'

@KaneCheshire
Copy link
Contributor

Yeah there you go, "Vorige" is Dutch for "Previous"

NavigationBar, 0x60000309a4c0, {{0.0, 58.0}, {414.0, 56.0}}, identifier: 'LargeTitleView'
   Button, 0x60000309a5a0, {{0.0, 64.0}, {44.0, 44.0}}, label: 'Vorige'

Cool so in your tests you could just use navBar.backButton(titled: "Vorige"), or you might be able to add an accessibilityIdentifier which would remain consistent between languages

@stefanrenne
Copy link
Author

Yeah there you go, "Vorige" is Dutch for "Previous"

NavigationBar, 0x60000309a4c0, {{0.0, 58.0}, {414.0, 56.0}}, identifier: 'LargeTitleView'
   Button, 0x60000309a5a0, {{0.0, 64.0}, {44.0, 44.0}}, label: 'Vorige'

Cool so in your tests you could just use navBar.backButton(titled: "Vorige"), or you might be able to add an accessibilityIdentifier which would remain consistent between languages

Sounds like a plan! I just reverted my previous commit & processed your feedback :)

@KaneCheshire KaneCheshire linked an issue Nov 5, 2020 that may be closed by this pull request
Copy link
Contributor

@theblixguy theblixguy left a comment

Choose a reason for hiding this comment

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

Looks great! Could you add some tests as well and update the changelog + readme?

TABTestKit/Classes/Elements/NavBar.swift Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@@ -14,6 +14,5 @@ struct TableSelectionScreen: Screen {

let trait = View(id: "TableSelection")
let navBar = NavBar()
let backButton = Button(id: "Table")

let backButton = NavBar().backButton(titled: "Table")
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be navBar.backButton instead?

Suggested change
let backButton = NavBar().backButton(titled: "Table")
let backButton = navBar.backButton(titled: "Table")

@stefanrenne stefanrenne deleted the feature/nav-back-button branch July 25, 2023 11:07
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.

Add back button support to NavBar
3 participants