Commit 15 of 23:
f49d66e4cd
fix(ios): keep tab accessory cleanup scoped to its native owner
previous
next
whole branch
Review threads live on the whole diff, not on one commit, so
none are shown here - a thread's line means something in the
branch's final form, and painting it into an intermediate
step would put it on code it is not about.
packages/ios/src/index.test.ts modified +1 -1 Changes to packages/ios/src/index.test.ts ⋯ 1,708 lines Show the 1,708 lines above this hunk @@ -1709,7 +1709,7 @@ describe('Craft iOS builder', () => { 1709 1709 1710 1710 expect ( screen ) . toContain ( 'if let hidden = options["tabBarHidden"] as? Bool {' ) 1711 1711 expect ( screen ) . toContain ( 'CraftChrome.shared.setHiddenByScreen(tabBarHidden)' ) 1712 - expect ( screen ) . toContain ( 'CraftChrome.shared. updateTabAccessory ( nil )' ) 1712 + expect ( screen ) . toContain ( 'CraftChrome.shared. clearTabAccessory ( ownedBy: self )' ) 1713 1713 expect ( screen ) . toContain ( 'if let contentSwipeBack = options["contentSwipeBack"] as? Bool {' ) 1714 1714 expect ( screen ) . toContain ( 'private(set) var contentSwipeBack = true' ) 1715 1715 expect ( screen ) . toContain ( 'if let tabSwipeEnabled = options["tabSwipeEnabled"] as? Bool {' )
packages/ios/templates/CraftApp.swift modified +9 -1 Changes to packages/ios/templates/CraftApp.swift ⋯ 669 lines Show the 669 lines above this hunk @@ -670,6 +670,7 @@ final class CraftChrome: ObservableObject { 670 670 671 671 @ Published var tabs : [ Tab ] = [ ] 672 672 @ Published var tabAccessory : Tab ? 673 + private weak var tabAccessoryOwner : AnyObject ? 673 674 @ Published var selected : String ? 674 675 let tabSwipeProgress = CraftTabSwipeProgress ( ) 675 676 private ( set ) var tabSwipePosition : CGFloat ? { ⋯ 95 lines Show the 95 lines above this hunk @@ -771,7 +772,7 @@ final class CraftChrome: ObservableObject { 771 772 tabs [ index ] = next 772 773 } 773 774 774 - func updateTabAccessory ( _ item : [ String : Any ] ? ) { 775 + func updateTabAccessory ( _ item : [ String : Any ] ? , owner : AnyObject ? = nil ) { 775 776 let next : Tab ? 776 777 if let item , let path = item [ "path" ] as ? String , 777 778 path . hasPrefix ( "/" ) , ! path . hasPrefix ( "//" ) , ⋯ 4 lines Show the 4 lines above this hunk @@ -782,10 +783,17 @@ final class CraftChrome: ObservableObject { 782 783 } else { 783 784 next = nil 784 785 } 786 + tabAccessoryOwner = owner 785 787 guard tabAccessory ! = next else { return } 786 788 tabAccessory = next 787 789 } 788 790 791 + 792 + func clearTabAccessory ( ownedBy owner : AnyObject ) { 793 + guard tabAccessoryOwner = = = owner else { return } 794 + updateTabAccessory ( nil ) 795 + } 796 + 789 797 func setHiddenByScreen ( _ hidden : Bool ) { 790 798 guard hiddenByScreen ! = hidden else { return } 791 799 hiddenByScreen = hidden
packages/ios/templates/CraftNativeScreen.swift modified +5 -6 Changes to packages/ios/templates/CraftNativeScreen.swift ⋯ 4,632 lines Show the 4,632 lines above this hunk @@ -4633,10 +4633,9 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate, 4633 4633 super . viewWillDisappear ( animated ) 4634 4634 screenVisibilityChanged ( false ) 4635 4635 stopCelebrations ( in : view ) 4636 - 4637 - 4638 - 4639 - CraftChrome . shared . updateTabAccessory ( nil ) 4636 + 4637 + 4638 + CraftChrome . shared . clearTabAccessory ( ownedBy : self ) 4640 4639 4641 4640 4642 4641 if tabBarHidden , isMovingFromParent | | isBeingDismissed | | navigationController ? . isBeingDismissed = = true { ⋯ 34 lines Show the 34 lines above this hunk @@ -4677,7 +4676,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate, 4677 4676 private func restoreShellChrome ( ) { 4678 4677 guard ! isAppScript else { return } 4679 4678 CraftChrome . shared . setHiddenByScreen ( tabBarHidden ) 4680 - CraftChrome . shared . updateTabAccessory ( tabAccessory ) 4679 + CraftChrome . shared . updateTabAccessory ( tabAccessory , owner : self ) 4681 4680 } 4682 4681 4683 4682 ⋯ 664 lines Show the 664 lines above this hunk @@ -5348,7 +5347,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate, 5348 5347 if options . keys . contains ( "tabAccessory" ) { 5349 5348 tabAccessory = options [ "tabAccessory" ] as ? [ String : Any ] 5350 5349 if navigationController ? . topViewController = = = self , view . window ! = nil { 5351 - CraftChrome . shared . updateTabAccessory ( tabAccessory ) 5350 + CraftChrome . shared . updateTabAccessory ( tabAccessory , owner : self ) 5352 5351 } 5353 5352 } 5354 5353 if options . keys . contains ( "title" ) {
scripts/native-renderer-contract.test.ts modified +1 -1 Changes to scripts/native-renderer-contract.test.ts ⋯ 2,923 lines Show the 2,923 lines above this hunk @@ -2924,7 +2924,7 @@ describe('native renderer component contract', () => { 2924 2924 expect ( iosNavigationTest ) . toContain ( 'craft-tab-accessory' ) 2925 2925 expect ( androidNavigationTest ) . toContain ( 'pushedScreenTabAccessoryOpensNativeRouteAndClearsOnBack' ) 2926 2926 expect ( androidNavigationTest ) . toContain ( 'Open capabilities' ) 2927 - expect ( ios ) . toContain ( 'CraftChrome.shared. updateTabAccessory ( nil )' ) 2927 + expect ( ios ) . toContain ( 'CraftChrome.shared. clearTabAccessory ( ownedBy: self )' ) 2928 2928 expect ( androidShell ) . toContain ( 'accessorySpec?.optString("path")?.let { onAccessory?.invoke(it) }' ) 2929 2929 expect ( guide ) . toContain ( '`tabAccessory` adds one destination button beside the tab pill' ) 2930 2930 expect ( iosReadme ) . toContain ( '`tabAccessory` destination beside the tab pill' )