Skip to main content

Firefox for iOS - Bug fixing

Open
SwiftFirefoxiOS-app
Contribution Types

These contributions are bug-fixes.

Introduction#

Firefox iOS presentation
Firefox iOS presentation

This contribution is composed of two PRs: Open Last Bookmark in 3D-touch and Misaligned texts in History Panel View.

Project#

You can find the Firefox for iOS project presentation here.

Open Last Bookmark in 3D-touch#

Context#

Firefox for iOS offers 3D Touch to help the user access commonly used features. By pressing the app icon on the Home Screen, the user can open the Quick Access menu which lets him quickly perform common app-specific tasks and see interesting information. In our case it has shortcuts to open a New Private Tab, scan QR Code... and open the last bookmark.

This shortcut displays the title and url of the last bookmarked website and open it on user tap.

Current behavior#

Currently when a bookmarked site is removed from the bookmark list, the "Open Last Bookmark" value from the Quick Access menu is not updated.

For example, when the user remove the last bookmark, the Quick Access menu keeps displaying it.

Implement the solution#

When we delete a bookmark, if it was the last one, we remove the shortcut otherwise we update the value of the last bookmark shortcut with the value of the most N - 1 recent one.

Bookmarks shortcut
3D-touch Last bookmark

In our case a user can directly access the last bookmarked site with profile.places.getRecentBookmarks(limit: 1).
If the bookmark items list response has a length of 0 (we have removed the last bookmarked website) then we remove the openLastBookmark shortcut with removeDynamicApplicationShortcutItemOfType otherwise we update the last bookmark site with the most recent one (addDynamicApplicationShortcutItemOfType).

Here is the code which implement the logic defined above.

Client/Frontend/Library/HistoryPanel.swift
// Get most recent bookmark
profile.places.getRecentBookmarks(limit: 1).uponQueue(.main) { result in
guard let bookmarkItems = result.successValue else { return }
if bookmarkItems.count == 0 {
// Remove the openLastBookmark shortcut
QuickActions.sharedInstance.removeDynamicApplicationShortcutItemOfType(
.openLastBookmark,
fromApplication: .shared)
} else {
// Update the last bookmark shortcut
let userData = [
QuickActions.TabURLKey: bookmarkItems[0].url,
QuickActions.TabTitleKey: bookm[0].title
]
QuickActions.sharedInstance.addDynamicApplicationShortcutItemOfType(
.openLastBookmark,
withUsuserData,
toApplication: .shared)
}
}

Final result#

Here is an example workflow demonstrating correct working of our logic.

  1. Add twitter.com to bookmark
  2. Add facebook.com to bookmark
  3. Go to bookmark shortcut (showing the facebook.com bookmark)
  4. Remove the facebook.com bookmark
  5. Go to bookmark shortcut (showing the twitter.com bookmark)
  6. Remove the twitter.com bookmark
  7. Go to bookmark shortcut
  8. Notice that the bookmark shortcut has disappeared

Misaligned texts in History Panel View#

Context#

Firefox for iOS has an History tab where you can find easily access to content you've already viewed.

Current behavior#

Currently the Clear Recent History and Recently closed cells have misaligned texts.
The goal of the contribution is to make the UI more consistent by aligning the labels in the cells.

Implement the solution#

The problem was that the components were using TwoLineImageOverlayCell (a cell with an image, a label and a description) instead of a OneLineTableViewCell (a cell which only use an image and a label) which is more appropriate to use in our case as it meets our need and the label is centered by default.

TwoLineImageOverlayCell and OneLineTableViewCell
TwoLineImageOverlayCell and OneLineTableViewCell

Before implementing our logic, the TwoLineImageOverlayCell was used with cell.descriptionLabel.isHidden = true to hide the description as the cells don't have description.

NOTE: isHidden is a Boolean value that determines whether the view is hidden or not.

The problem was that hidden views still participate in Auto Layout and retain their frames, leaving other related views in their places meaning that the description layout will still affect our cell UI.

As said above, the solution is to use OneLineTableViewCell when we configure the tableView.

Client/Frontend/Library/HistoryPanel.swift
let oneLineCell = tableView.dequeueReusableCell(
withIdentifier: OneLineCellIdentifier,
for: indexPath
) as! OneLineTableViewCell
switch row {
case .clearRecent:
return configureClearHistory(oneLineCell, for: indexPath)
case .showRecentlyClosedTabs:
return configureRecentlyClosed(oneLineCell, for: indexPath)
}

Final result#

Here is the final result showing the History tab with the texts correctly aligned.

Misaligned
Misaligned texts in History Panel View

Takeaway#

Problems encountered#

The code exploration was the part that took me the most time.
In addition, I'm not accustomed to using XCode in my everyday developer life so I had to adapt to a different IDE than the one I usually use.

What did I learn ?#

This was my first contribution in Swift to an iOS app so it taught me a lot !
Not being an iOS user, I also learned about 3D Touch in its use case in a real app.