@@ -53,6 +53,10 @@ final class ProductFormViewController<ViewModel: ProductFormViewModelProtocol>:
5353 presentationStyle. createExitForm ( viewController: self )
5454 } ( )
5555
56+ private lazy var shareBarButtonItem = UIBarButtonItem ( barButtonSystemItem: . action,
57+ target: self ,
58+ action: #selector( shareProduct) )
59+
5660 private let presentationStyle : ProductFormPresentationStyle
5761 private let navigationRightBarButtonItemsSubject = PassthroughSubject < [ UIBarButtonItem ] , Never > ( )
5862 private var navigationRightBarButtonItems : AnyPublisher < [ UIBarButtonItem ] , Never > {
@@ -281,7 +285,7 @@ final class ProductFormViewController<ViewModel: ProductFormViewModelProtocol>:
281285
282286 if viewModel. canShareProduct ( ) {
283287 actionSheet. addDefaultActionWithTitle ( ActionSheetStrings . share) { [ weak self] _ in
284- self ? . displayShareProduct ( source : . moreMenu)
288+ self ? . displayShareProduct ( from : sender , analyticSource : . moreMenu)
285289 }
286290 }
287291
@@ -470,7 +474,7 @@ final class ProductFormViewController<ViewModel: ProductFormViewModelProtocol>:
470474 }
471475
472476 @objc private func shareProduct( ) {
473- displayShareProduct ( source : . productForm)
477+ displayShareProduct ( from : shareBarButtonItem , analyticSource : . productForm)
474478 }
475479
476480 func tableView( _ tableView: UITableView , heightForHeaderInSection section: Int ) -> CGFloat {
@@ -861,14 +865,14 @@ private extension ProductFormViewController {
861865 WebviewHelper . launch ( url, with: self )
862866 }
863867
864- func displayShareProduct( source : WooAnalyticsEvent . ProductForm . ShareProductSource ) {
865- ServiceLocator . analytics. track ( event: . ProductForm. productDetailShareButtonTapped ( source: source ) )
868+ func displayShareProduct( from sourceView : UIBarButtonItem , analyticSource : WooAnalyticsEvent . ProductForm . ShareProductSource ) {
869+ ServiceLocator . analytics. track ( event: . ProductForm. productDetailShareButtonTapped ( source: analyticSource ) )
866870
867871 guard let url = URL ( string: product. permalink) else {
868872 return
869873 }
870874
871- SharingHelper . shareURL ( url: url, title: product. name, from: view , in: self )
875+ SharingHelper . shareURL ( url: url, title: product. name, from: sourceView , in: self )
872876 }
873877
874878 func duplicateProduct( ) {
@@ -1009,7 +1013,7 @@ private extension ProductFormViewController {
10091013 case . more:
10101014 return createMoreOptionsBarButtonItem ( )
10111015 case . share:
1012- return createShareBarButtonItem ( )
1016+ return shareBarButtonItem
10131017 }
10141018 }
10151019
@@ -1055,12 +1059,6 @@ private extension ProductFormViewController {
10551059 moreButton. accessibilityIdentifier = " edit-product-more-options-button "
10561060 return moreButton
10571061 }
1058-
1059- func createShareBarButtonItem( ) -> UIBarButtonItem {
1060- UIBarButtonItem ( barButtonSystemItem: . action,
1061- target: self ,
1062- action: #selector( shareProduct) )
1063- }
10641062}
10651063
10661064// MARK: - Keyboard management
0 commit comments