Search code examples
iosswiftxcodexcuitestsfsafariviewcontroller

Will SFSafariViewController always have the same UI elements in the navigation bar and the bottom toolbar?


I have an app that uses a SFSafariViewController. The user clicks on a button and a webview appears inside the app presenting the contents of the site. I'm using XCUITest framework to test the UI.

I notice that when the webview appears, the navigation bar and the bottom tool bar seem to always have the same UI elements.

Navigation Bar UI Elements (going from left to right):

enter image description here

  1. "Done" Button
  2. URL link
  3. Reload button

Bottom Tool Bar UI Elements (going from left to right):

enter image description here

  1. Back arrow button
  2. Forward arrow button
  3. Share button
  4. Open In Safari button

From a UI test standpoint, can I assume that these UI elements will always be present as default for a SFSafari VC?


Solution

  • You can see the full configuration available for SFSafariViewController here: https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/dismissbuttonstyle. From what I can see, here's what can be configured out of the box:

    1. The "done" button on the top left can be changed to look differently (Done, Close and Cancel are the options): https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/dismissbuttonstyle
    2. You can make the top nav bar "collapsable" with the barCollapsingEnabled property. https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/configuration/2887469-barcollapsingenabled

    3. You can change the preferred tint colors of the bar and the controls (buttons).

    Other than that, SFSafariViewController has few options available for customization.

    So the answer to your question is: No, you can't assume these elements will always be present. However, in most scenarios they will be. In general, I wouldn't assume anything anyway, because Apple could always change it in future iOS versions.