Skip to content

Commit

Permalink
Add FXIOS-9468 Add share button to address toolbar (#20999)
Browse files Browse the repository at this point in the history
* Add share action to address toolbar

* Fix bug were navigation buttons were not shown

* Apply theme to navigation toolbar buttons

* Fix address toolbar divider color

* Show only QR code page action when editing

* Fix bug where share was shown multiple times

* Fix tests
  • Loading branch information
thatswinnie authored Jul 15, 2024
1 parent 5a85a66 commit dfecf3e
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public class BrowserAddressToolbar: UIView, AddressToolbar, ThemeApplicable, Loc
public func applyTheme(theme: Theme) {
backgroundColor = theme.colors.layer1
locationContainer.backgroundColor = theme.colors.layerSearch
locationDividerView.backgroundColor = theme.colors.layer2
locationDividerView.backgroundColor = theme.colors.layer1
toolbarTopBorderView.backgroundColor = theme.colors.borderPrimary
toolbarBottomBorderView.backgroundColor = theme.colors.borderPrimary
locationView.applyTheme(theme: theme)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public class BrowserNavigationToolbar: UIView, NavigationToolbar, ThemeApplicabl
public func applyTheme(theme: Theme) {
backgroundColor = theme.colors.layer1
toolbarBorderView.backgroundColor = theme.colors.borderPrimary

actionStack.arrangedSubviews.forEach { element in
guard let button = element as? ToolbarButton else { return }
button.applyTheme(theme: theme)
}

self.theme = theme
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum GeneralBrowserActionType: ActionType {
case showMenu
case stopLoadingWebsite
case reloadWebsite
case showShare
}

class GeneralBrowserMiddlewareAction: Action {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,7 @@ extension BrowserViewController: URLBarDelegate {
}

func urlBarDidPressShare(_ urlBar: URLBarView, shareView: UIView) {
TelemetryWrapper.recordEvent(category: .action,
method: .tap,
object: .awesomebarLocation,
value: .awesomebarShareTap,
extras: nil)

if let selectedtab = tabManager.selectedTab, let tabUrl = selectedtab.canonicalURL?.displayURL {
navigationHandler?.showShareExtension(
url: tabUrl,
sourceView: shareView,
toastContainer: contentContainer,
popoverArrowDirection: isBottomSearchBar ? .down : .up)
}
didTapOnShare(from: shareView)
}

internal func dismissFakespotIfNeeded(animated: Bool = true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct BrowserViewControllerState: ScreenState, Equatable {
case tabsLongPressActions
case menu
case tabTray
case share
}

let windowUUID: WindowUUID
Expand All @@ -33,8 +34,8 @@ struct BrowserViewControllerState: ScreenState, Equatable {
var showOverlay: Bool
var reloadWebView: Bool
var browserViewType: BrowserViewType
var navigateTo: NavigationType?
var displayView: DisplayType?
var navigateTo: NavigationType? // use default value when re-creating
var displayView: DisplayType? // use default value when re-creating
var buttonTapped: UIButton?
var microsurveyState: MicrosurveyPromptState

Expand Down Expand Up @@ -170,7 +171,14 @@ struct BrowserViewControllerState: ScreenState, Equatable {
browserViewType: browserViewType,
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action))
default:
return state
return BrowserViewControllerState(
searchScreenState: state.searchScreenState,
showDataClearanceFlow: state.showDataClearanceFlow,
fakespotState: state.fakespotState,
windowUUID: state.windowUUID,
reloadWebView: state.reloadWebView,
browserViewType: state.browserViewType,
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action))
}
}

Expand Down Expand Up @@ -310,6 +318,17 @@ struct BrowserViewControllerState: ScreenState, Equatable {
browserViewType: state.browserViewType,
navigateTo: .stopLoading,
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action))
case GeneralBrowserActionType.showShare:
return BrowserViewControllerState(
searchScreenState: state.searchScreenState,
showDataClearanceFlow: state.showDataClearanceFlow,
fakespotState: state.fakespotState,
toast: state.toast,
windowUUID: state.windowUUID,
browserViewType: state.browserViewType,
displayView: .share,
buttonTapped: action.buttonTapped,
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action))
default:
return state
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1768,8 +1768,8 @@ class BrowserViewController: UIViewController,
url: tab.url?.displayURL,
lockIconImageName: lockIconImageName,
isShowingNavigationToolbar: ToolbarHelper().shouldShowNavigationToolbar(for: traitCollection),
canGoForward: tab.canGoForward,
canGoBack: tab.canGoBack,
canGoForward: tab.canGoForward,
windowUUID: windowUUID,
actionType: ToolbarMiddlewareActionType.urlDidChange)
store.dispatch(action)
Expand Down Expand Up @@ -1842,11 +1842,12 @@ class BrowserViewController: UIViewController,
}

private func dispatchBackForwardToolbarAction(_ isEnabled: Bool?, _ windowUUID: UUID, _ actionType: ToolbarActionType) {
let action = ToolbarAction(isButtonEnabled: isEnabled, windowUUID: windowUUID, actionType: actionType)

switch actionType {
case .backButtonStateChanged,
.forwardButtonStateChanged:
case .backButtonStateChanged:
let action = ToolbarAction(canGoBack: isEnabled, windowUUID: windowUUID, actionType: actionType)
store.dispatch(action)
case .forwardButtonStateChanged:
let action = ToolbarAction(canGoForward: isEnabled, windowUUID: windowUUID, actionType: actionType)
store.dispatch(action)
default: break
}
Expand Down Expand Up @@ -1875,6 +1876,9 @@ class BrowserViewController: UIViewController,
object: .tabToolbar,
value: .tabView
)
case .share:
guard let button = state.buttonTapped else { return }
didTapOnShare(from: button)
}
}

Expand Down Expand Up @@ -1973,6 +1977,22 @@ class BrowserViewController: UIViewController,
}
}

func didTapOnShare(from view: UIView) {
TelemetryWrapper.recordEvent(category: .action,
method: .tap,
object: .awesomebarLocation,
value: .awesomebarShareTap,
extras: nil)

if let selectedTab = tabManager.selectedTab, let tabUrl = selectedTab.canonicalURL?.displayURL {
navigationHandler?.showShareExtension(
url: tabUrl,
sourceView: view,
toastContainer: contentContainer,
popoverArrowDirection: isBottomSearchBar ? .down : .up)
}
}

func presentActionSheet(from view: UIView) {
guard presentedViewController == nil else { return }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct AddressBarState: StateType, Equatable {
return AddressBarState(
windowUUID: state.windowUUID,
navigationActions: addressToolbarModel?.navigationActions ?? state.navigationActions,
pageActions: state.pageActions,
pageActions: addressToolbarModel?.pageActions ?? state.pageActions,
browserActions: state.browserActions,
borderPosition: state.borderPosition,
url: toolbarAction.url,
Expand All @@ -115,12 +115,12 @@ struct AddressBarState: StateType, Equatable {
)

case ToolbarActionType.backButtonStateChanged:
guard let isEnabled = (action as? ToolbarAction)?.isButtonEnabled else { return state }
guard let canGoBack = (action as? ToolbarAction)?.canGoBack else { return state }

var actions = state.navigationActions

if let index = actions.firstIndex(where: { $0.actionType == .back }) {
actions[index].isEnabled = isEnabled
actions[index].isEnabled = canGoBack
}

return AddressBarState(
Expand All @@ -134,12 +134,12 @@ struct AddressBarState: StateType, Equatable {
)

case ToolbarActionType.forwardButtonStateChanged:
guard let isEnabled = (action as? ToolbarAction)?.isButtonEnabled else { return state }
guard let canGoForward = (action as? ToolbarAction)?.canGoForward else { return state }

var actions = state.navigationActions

if let index = actions.firstIndex(where: { $0.actionType == .forward }) {
actions[index].isEnabled = isEnabled
actions[index].isEnabled = canGoForward
}

return AddressBarState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ struct NavigationBarState: StateType, Equatable {
)

case ToolbarActionType.backButtonStateChanged:
guard let isEnabled = (action as? ToolbarAction)?.isButtonEnabled else { return state }
guard let canGoBack = (action as? ToolbarAction)?.canGoBack else { return state }

var actions = state.actions

if let index = actions.firstIndex(where: { $0.actionType == .back }) {
actions[index].isEnabled = isEnabled
actions[index].isEnabled = canGoBack
}

return NavigationBarState(
Expand All @@ -69,12 +69,12 @@ struct NavigationBarState: StateType, Equatable {
)

case ToolbarActionType.forwardButtonStateChanged:
guard let isEnabled = (action as? ToolbarAction)?.isButtonEnabled else { return state }
guard let canGoForward = (action as? ToolbarAction)?.canGoForward else { return state }

var actions = state.actions

if let index = actions.firstIndex(where: { $0.actionType == .forward }) {
actions[index].isEnabled = isEnabled
actions[index].isEnabled = canGoForward
}

return NavigationBarState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,34 @@ class ToolbarAction: Action {
let toolbarPosition: AddressToolbarPosition?
let numberOfTabs: Int?
let url: URL?
let isButtonEnabled: Bool?
let isPrivate: Bool?
let badgeImageName: String?
let isShowingNavigationToolbar: Bool?
let canGoBack: Bool?
let canGoForward: Bool?

init(addressToolbarModel: AddressToolbarModel? = nil,
navigationToolbarModel: NavigationToolbarModel? = nil,
toolbarPosition: AddressToolbarPosition? = nil,
numberOfTabs: Int? = nil,
url: URL? = nil,
isButtonEnabled: Bool? = nil,
isPrivate: Bool? = nil,
badgeImageName: String? = nil,
isShowingNavigationToolbar: Bool? = nil,
canGoBack: Bool? = nil,
canGoForward: Bool? = nil,
windowUUID: WindowUUID,
actionType: ActionType) {
self.addressToolbarModel = addressToolbarModel
self.navigationToolbarModel = navigationToolbarModel
self.toolbarPosition = toolbarPosition
self.numberOfTabs = numberOfTabs
self.url = url
self.isButtonEnabled = isButtonEnabled
self.isPrivate = isPrivate
self.badgeImageName = badgeImageName
self.isShowingNavigationToolbar = isShowingNavigationToolbar
self.canGoBack = canGoBack
self.canGoForward = canGoForward
super.init(windowUUID: windowUUID, actionType: actionType)
}
}
Expand Down Expand Up @@ -74,21 +80,21 @@ final class ToolbarMiddlewareUrlChangeAction: ToolbarMiddlewareAction {
let url: URL?
let lockIconImageName: String
let isShowingNavigationToolbar: Bool
let canGoForward: Bool
let canGoBack: Bool
let canGoForward: Bool

init(url: URL? = nil,
lockIconImageName: String,
isShowingNavigationToolbar: Bool,
canGoForward: Bool,
canGoBack: Bool,
canGoForward: Bool,
windowUUID: WindowUUID,
actionType: ActionType) {
self.url = url
self.lockIconImageName = lockIconImageName
self.isShowingNavigationToolbar = isShowingNavigationToolbar
self.canGoForward = canGoForward
self.canGoBack = canGoBack
self.canGoForward = canGoForward
super.init(windowUUID: windowUUID, actionType: actionType)
}
}
Expand Down
Loading

0 comments on commit dfecf3e

Please sign in to comment.