Skip to content

Commit

Permalink
Add FXIOS-9118 - Add long press action to tabs button (#20586)
Browse files Browse the repository at this point in the history
  • Loading branch information
PARAIPAN9 authored Jun 7, 2024
1 parent dd5cd65 commit b41ea57
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum GeneralBrowserActionType: ActionType {
case showTabTray
case showQRcodeReader
case showBackForwardList
case showTabsLongPressActions
}

class GeneralBrowserMiddlewareAction: Action {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,10 @@ extension BrowserViewController: TabToolbarDelegate, PhotonActionSheetProtocol {
}

func tabToolbarDidLongPressTabs(_ tabToolbar: TabToolbarProtocol, button: UIButton) {
guard self.presentedViewController == nil else { return }
var actions: [[PhotonRowActions]] = []
actions.append(getTabToolbarLongPressActionsForModeSwitching())
actions.append(getMoreTabToolbarLongPressActions())

let generator = UIImpactFeedbackGenerator(style: .heavy)
generator.impactOccurred()

let viewModel = PhotonActionSheetViewModel(
actions: actions,
closeButtonTitle: .CloseButtonTitle,
modalStyle: .overCurrentContext
)
presentSheetWith(viewModel: viewModel, on: self, from: button)
presentActionSheet(from: button)
}

func tabToolbarDidPressSearch(_ tabToolbar: TabToolbarProtocol, button: UIButton) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct BrowserViewControllerState: ScreenState, Equatable {
var navigateTo: NavigationType?
var showQRcodeReader: Bool
var showBackForwardList: Bool
var showTabsLongPressActions: Bool
var microsurveyState: MicrosurveyPromptState

init(appState: AppState, uuid: WindowUUID) {
Expand All @@ -51,6 +52,7 @@ struct BrowserViewControllerState: ScreenState, Equatable {
navigateTo: bvcState.navigateTo,
showQRcodeReader: bvcState.showQRcodeReader,
showBackForwardList: bvcState.showBackForwardList,
showTabsLongPressActions: bvcState.showTabsLongPressActions,
microsurveyState: bvcState.microsurveyState)
}

Expand All @@ -67,6 +69,7 @@ struct BrowserViewControllerState: ScreenState, Equatable {
navigateTo: nil,
showQRcodeReader: false,
showBackForwardList: false,
showTabsLongPressActions: false,
microsurveyState: MicrosurveyPromptState(windowUUID: windowUUID))
}

Expand All @@ -83,6 +86,7 @@ struct BrowserViewControllerState: ScreenState, Equatable {
navigateTo: NavigationType? = nil,
showQRcodeReader: Bool = false,
showBackForwardList: Bool = false,
showTabsLongPressActions: Bool = false,
microsurveyState: MicrosurveyPromptState
) {
self.searchScreenState = searchScreenState
Expand All @@ -97,6 +101,7 @@ struct BrowserViewControllerState: ScreenState, Equatable {
self.navigateTo = navigateTo
self.showQRcodeReader = showQRcodeReader
self.showBackForwardList = showBackForwardList
self.showTabsLongPressActions = showTabsLongPressActions
self.microsurveyState = microsurveyState
}

Expand Down Expand Up @@ -251,6 +256,20 @@ struct BrowserViewControllerState: ScreenState, Equatable {
showQRcodeReader: false,
showBackForwardList: true,
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action))
case GeneralBrowserActionType.showTabsLongPressActions:
return BrowserViewControllerState(
searchScreenState: state.searchScreenState,
showDataClearanceFlow: state.showDataClearanceFlow,
toolbarState: state.toolbarState,
fakespotState: state.fakespotState,
toast: state.toast,
windowUUID: state.windowUUID,
browserViewType: state.browserViewType,
navigateTo: nil,
showQRcodeReader: false,
showBackForwardList: false,
showTabsLongPressActions: true,
microsurveyState: MicrosurveyPromptState.reducer(state.microsurveyState, action))
case GeneralBrowserActionType.navigateBack:
return BrowserViewControllerState(
searchScreenState: state.searchScreenState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,8 @@ class BrowserViewController: UIViewController,
navigationHandler?.showQRCode(delegate: self)
} else if state.showBackForwardList {
navigationHandler?.showBackForwardList()
} else if state.showTabsLongPressActions {
presentActionSheet(from: view)
}
}

Expand Down Expand Up @@ -1860,6 +1862,22 @@ class BrowserViewController: UIViewController,
tabManager.selectedTab?.goForward()
}

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

var actions: [[PhotonRowActions]] = []
actions.append(getTabToolbarLongPressActionsForModeSwitching())
actions.append(getMoreTabToolbarLongPressActions())

let viewModel = PhotonActionSheetViewModel(
actions: actions,
closeButtonTitle: .CloseButtonTitle,
modalStyle: .overCurrentContext
)

presentSheetWith(viewModel: viewModel, on: self, from: view)
}

func focusOnTabSegment() {
let isPrivateTab = tabManager.selectedTab?.isPrivate ?? false
let segmentToFocus = isPrivateTab ? TabTrayPanelType.privateTabs : TabTrayPanelType.tabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ class ToolbarMiddleware: FeatureFlaggable {
let action = GeneralBrowserAction(windowUUID: windowUUID,
actionType: GeneralBrowserActionType.showBackForwardList)
store.dispatch(action)
case .tabs:
let action = GeneralBrowserAction(windowUUID: windowUUID,
actionType: GeneralBrowserActionType.showTabsLongPressActions)
store.dispatch(action)
default:
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ struct ToolbarState: ScreenState, Equatable {

var canPerformLongPressAction: Bool {
return actionType == .back ||
actionType == .forward
actionType == .forward ||
actionType == .tabs
}
}

Expand Down

0 comments on commit b41ea57

Please sign in to comment.