Skip to content

Commit dfecf3e

Browse files
authored
Add FXIOS-9468 Add share button to address toolbar (mozilla-mobile#20999)
* 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
1 parent 5a85a66 commit dfecf3e

File tree

12 files changed

+171
-90
lines changed

12 files changed

+171
-90
lines changed

BrowserKit/Sources/ToolbarKit/AddressToolbar/BrowserAddressToolbar.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public class BrowserAddressToolbar: UIView, AddressToolbar, ThemeApplicable, Loc
269269
public func applyTheme(theme: Theme) {
270270
backgroundColor = theme.colors.layer1
271271
locationContainer.backgroundColor = theme.colors.layerSearch
272-
locationDividerView.backgroundColor = theme.colors.layer2
272+
locationDividerView.backgroundColor = theme.colors.layer1
273273
toolbarTopBorderView.backgroundColor = theme.colors.borderPrimary
274274
toolbarBottomBorderView.backgroundColor = theme.colors.borderPrimary
275275
locationView.applyTheme(theme: theme)

BrowserKit/Sources/ToolbarKit/NavigationToolbar/BrowserNavigationToolbar.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public class BrowserNavigationToolbar: UIView, NavigationToolbar, ThemeApplicabl
7979
public func applyTheme(theme: Theme) {
8080
backgroundColor = theme.colors.layer1
8181
toolbarBorderView.backgroundColor = theme.colors.borderPrimary
82+
83+
actionStack.arrangedSubviews.forEach { element in
84+
guard let button = element as? ToolbarButton else { return }
85+
button.applyTheme(theme: theme)
86+
}
87+
8288
self.theme = theme
8389
}
8490
}

firefox-ios/Client/Frontend/Browser/BrowserViewController/Actions/GeneralBrowserAction.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum GeneralBrowserActionType: ActionType {
4545
case showMenu
4646
case stopLoadingWebsite
4747
case reloadWebsite
48+
case showShare
4849
}
4950

5051
class GeneralBrowserMiddlewareAction: Action {

firefox-ios/Client/Frontend/Browser/BrowserViewController/Extensions/BrowserViewController+URLBarDelegate.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,7 @@ extension BrowserViewController: URLBarDelegate {
105105
}
106106

107107
func urlBarDidPressShare(_ urlBar: URLBarView, shareView: UIView) {
108-
TelemetryWrapper.recordEvent(category: .action,
109-
method: .tap,
110-
object: .awesomebarLocation,
111-
value: .awesomebarShareTap,
112-
extras: nil)
113-
114-
if let selectedtab = tabManager.selectedTab, let tabUrl = selectedtab.canonicalURL?.displayURL {
115-
navigationHandler?.showShareExtension(
116-
url: tabUrl,
117-
sourceView: shareView,
118-
toastContainer: contentContainer,
119-
popoverArrowDirection: isBottomSearchBar ? .down : .up)
120-
}
108+
didTapOnShare(from: shareView)
121109
}
122110

123111
internal func dismissFakespotIfNeeded(animated: Bool = true) {

firefox-ios/Client/Frontend/Browser/BrowserViewController/State/BrowserViewControllerState.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct BrowserViewControllerState: ScreenState, Equatable {
2323
case tabsLongPressActions
2424
case menu
2525
case tabTray
26+
case share
2627
}
2728

2829
let windowUUID: WindowUUID
@@ -33,8 +34,8 @@ struct BrowserViewControllerState: ScreenState, Equatable {
3334
var showOverlay: Bool
3435
var reloadWebView: Bool
3536
var browserViewType: BrowserViewType
36-
var navigateTo: NavigationType?
37-
var displayView: DisplayType?
37+
var navigateTo: NavigationType? // use default value when re-creating
38+
var displayView: DisplayType? // use default value when re-creating
3839
var buttonTapped: UIButton?
3940
var microsurveyState: MicrosurveyPromptState
4041

@@ -170,7 +171,14 @@ struct BrowserViewControllerState: ScreenState, Equatable {
170171
browserViewType: browserViewType,
171172
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action))
172173
default:
173-
return state
174+
return BrowserViewControllerState(
175+
searchScreenState: state.searchScreenState,
176+
showDataClearanceFlow: state.showDataClearanceFlow,
177+
fakespotState: state.fakespotState,
178+
windowUUID: state.windowUUID,
179+
reloadWebView: state.reloadWebView,
180+
browserViewType: state.browserViewType,
181+
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action))
174182
}
175183
}
176184

@@ -310,6 +318,17 @@ struct BrowserViewControllerState: ScreenState, Equatable {
310318
browserViewType: state.browserViewType,
311319
navigateTo: .stopLoading,
312320
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action))
321+
case GeneralBrowserActionType.showShare:
322+
return BrowserViewControllerState(
323+
searchScreenState: state.searchScreenState,
324+
showDataClearanceFlow: state.showDataClearanceFlow,
325+
fakespotState: state.fakespotState,
326+
toast: state.toast,
327+
windowUUID: state.windowUUID,
328+
browserViewType: state.browserViewType,
329+
displayView: .share,
330+
buttonTapped: action.buttonTapped,
331+
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action))
313332
default:
314333
return state
315334
}

firefox-ios/Client/Frontend/Browser/BrowserViewController/Views/BrowserViewController.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,8 +1768,8 @@ class BrowserViewController: UIViewController,
17681768
url: tab.url?.displayURL,
17691769
lockIconImageName: lockIconImageName,
17701770
isShowingNavigationToolbar: ToolbarHelper().shouldShowNavigationToolbar(for: traitCollection),
1771-
canGoForward: tab.canGoForward,
17721771
canGoBack: tab.canGoBack,
1772+
canGoForward: tab.canGoForward,
17731773
windowUUID: windowUUID,
17741774
actionType: ToolbarMiddlewareActionType.urlDidChange)
17751775
store.dispatch(action)
@@ -1842,11 +1842,12 @@ class BrowserViewController: UIViewController,
18421842
}
18431843

18441844
private func dispatchBackForwardToolbarAction(_ isEnabled: Bool?, _ windowUUID: UUID, _ actionType: ToolbarActionType) {
1845-
let action = ToolbarAction(isButtonEnabled: isEnabled, windowUUID: windowUUID, actionType: actionType)
1846-
18471845
switch actionType {
1848-
case .backButtonStateChanged,
1849-
.forwardButtonStateChanged:
1846+
case .backButtonStateChanged:
1847+
let action = ToolbarAction(canGoBack: isEnabled, windowUUID: windowUUID, actionType: actionType)
1848+
store.dispatch(action)
1849+
case .forwardButtonStateChanged:
1850+
let action = ToolbarAction(canGoForward: isEnabled, windowUUID: windowUUID, actionType: actionType)
18501851
store.dispatch(action)
18511852
default: break
18521853
}
@@ -1875,6 +1876,9 @@ class BrowserViewController: UIViewController,
18751876
object: .tabToolbar,
18761877
value: .tabView
18771878
)
1879+
case .share:
1880+
guard let button = state.buttonTapped else { return }
1881+
didTapOnShare(from: button)
18781882
}
18791883
}
18801884

@@ -1973,6 +1977,22 @@ class BrowserViewController: UIViewController,
19731977
}
19741978
}
19751979

1980+
func didTapOnShare(from view: UIView) {
1981+
TelemetryWrapper.recordEvent(category: .action,
1982+
method: .tap,
1983+
object: .awesomebarLocation,
1984+
value: .awesomebarShareTap,
1985+
extras: nil)
1986+
1987+
if let selectedTab = tabManager.selectedTab, let tabUrl = selectedTab.canonicalURL?.displayURL {
1988+
navigationHandler?.showShareExtension(
1989+
url: tabUrl,
1990+
sourceView: view,
1991+
toastContainer: contentContainer,
1992+
popoverArrowDirection: isBottomSearchBar ? .down : .up)
1993+
}
1994+
}
1995+
19761996
func presentActionSheet(from view: UIView) {
19771997
guard presentedViewController == nil else { return }
19781998

firefox-ios/Client/Frontend/Browser/Toolbars/Redux/AddressBarState.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct AddressBarState: StateType, Equatable {
106106
return AddressBarState(
107107
windowUUID: state.windowUUID,
108108
navigationActions: addressToolbarModel?.navigationActions ?? state.navigationActions,
109-
pageActions: state.pageActions,
109+
pageActions: addressToolbarModel?.pageActions ?? state.pageActions,
110110
browserActions: state.browserActions,
111111
borderPosition: state.borderPosition,
112112
url: toolbarAction.url,
@@ -115,12 +115,12 @@ struct AddressBarState: StateType, Equatable {
115115
)
116116

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

120120
var actions = state.navigationActions
121121

122122
if let index = actions.firstIndex(where: { $0.actionType == .back }) {
123-
actions[index].isEnabled = isEnabled
123+
actions[index].isEnabled = canGoBack
124124
}
125125

126126
return AddressBarState(
@@ -134,12 +134,12 @@ struct AddressBarState: StateType, Equatable {
134134
)
135135

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

139139
var actions = state.navigationActions
140140

141141
if let index = actions.firstIndex(where: { $0.actionType == .forward }) {
142-
actions[index].isEnabled = isEnabled
142+
actions[index].isEnabled = canGoForward
143143
}
144144

145145
return AddressBarState(

firefox-ios/Client/Frontend/Browser/Toolbars/Redux/NavigationBarState.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ struct NavigationBarState: StateType, Equatable {
5454
)
5555

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

5959
var actions = state.actions
6060

6161
if let index = actions.firstIndex(where: { $0.actionType == .back }) {
62-
actions[index].isEnabled = isEnabled
62+
actions[index].isEnabled = canGoBack
6363
}
6464

6565
return NavigationBarState(
@@ -69,12 +69,12 @@ struct NavigationBarState: StateType, Equatable {
6969
)
7070

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

7474
var actions = state.actions
7575

7676
if let index = actions.firstIndex(where: { $0.actionType == .forward }) {
77-
actions[index].isEnabled = isEnabled
77+
actions[index].isEnabled = canGoForward
7878
}
7979

8080
return NavigationBarState(

firefox-ios/Client/Frontend/Browser/Toolbars/Redux/ToolbarAction.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,34 @@ class ToolbarAction: Action {
1212
let toolbarPosition: AddressToolbarPosition?
1313
let numberOfTabs: Int?
1414
let url: URL?
15-
let isButtonEnabled: Bool?
1615
let isPrivate: Bool?
1716
let badgeImageName: String?
17+
let isShowingNavigationToolbar: Bool?
18+
let canGoBack: Bool?
19+
let canGoForward: Bool?
1820

1921
init(addressToolbarModel: AddressToolbarModel? = nil,
2022
navigationToolbarModel: NavigationToolbarModel? = nil,
2123
toolbarPosition: AddressToolbarPosition? = nil,
2224
numberOfTabs: Int? = nil,
2325
url: URL? = nil,
24-
isButtonEnabled: Bool? = nil,
2526
isPrivate: Bool? = nil,
2627
badgeImageName: String? = nil,
28+
isShowingNavigationToolbar: Bool? = nil,
29+
canGoBack: Bool? = nil,
30+
canGoForward: Bool? = nil,
2731
windowUUID: WindowUUID,
2832
actionType: ActionType) {
2933
self.addressToolbarModel = addressToolbarModel
3034
self.navigationToolbarModel = navigationToolbarModel
3135
self.toolbarPosition = toolbarPosition
3236
self.numberOfTabs = numberOfTabs
3337
self.url = url
34-
self.isButtonEnabled = isButtonEnabled
3538
self.isPrivate = isPrivate
3639
self.badgeImageName = badgeImageName
40+
self.isShowingNavigationToolbar = isShowingNavigationToolbar
41+
self.canGoBack = canGoBack
42+
self.canGoForward = canGoForward
3743
super.init(windowUUID: windowUUID, actionType: actionType)
3844
}
3945
}
@@ -74,21 +80,21 @@ final class ToolbarMiddlewareUrlChangeAction: ToolbarMiddlewareAction {
7480
let url: URL?
7581
let lockIconImageName: String
7682
let isShowingNavigationToolbar: Bool
77-
let canGoForward: Bool
7883
let canGoBack: Bool
84+
let canGoForward: Bool
7985

8086
init(url: URL? = nil,
8187
lockIconImageName: String,
8288
isShowingNavigationToolbar: Bool,
83-
canGoForward: Bool,
8489
canGoBack: Bool,
90+
canGoForward: Bool,
8591
windowUUID: WindowUUID,
8692
actionType: ActionType) {
8793
self.url = url
8894
self.lockIconImageName = lockIconImageName
8995
self.isShowingNavigationToolbar = isShowingNavigationToolbar
90-
self.canGoForward = canGoForward
9196
self.canGoBack = canGoBack
97+
self.canGoForward = canGoForward
9298
super.init(windowUUID: windowUUID, actionType: actionType)
9399
}
94100
}

0 commit comments

Comments
 (0)