diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3e46c94..e80515a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,6 +36,18 @@ To invoke **Nitrogen**, use the following command: yarn nitrogen ``` +This command also reapplies the required Fabric unmount patch to: + +```sh +nitrogen/generated/ios/c++/views/HybridRNScrollEdgeBarComponent.mm +``` + +Do not run `nitrogen` directly unless you also rerun: + +```sh +yarn nitrogen:patch +``` + The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make. It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app. diff --git a/example/src/App.tsx b/example/src/App.tsx index 066a305..3d17d77 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -103,7 +103,6 @@ export default function App() { title: 'Transition Showcase', headerShadowVisible: false, headerTransparent: true, - headerLargeTitleEnabled: true, headerBackButtonDisplayMode: 'minimal', headerTintColor: DynamicColorIOS({ light: 'black', diff --git a/example/src/screens/CalendarScreen.tsx b/example/src/screens/CalendarScreen.tsx index 7fbd2be..7be1883 100644 --- a/example/src/screens/CalendarScreen.tsx +++ b/example/src/screens/CalendarScreen.tsx @@ -147,6 +147,7 @@ export function CalendarScreen() { const styles = StyleSheet.create({ container: { flex: 1, + backgroundColor: 'white', }, topBar: { paddingHorizontal: 0, diff --git a/ios/HybridScrollEdgeBar.swift b/ios/HybridScrollEdgeBar.swift index a0ad584..28bc595 100644 --- a/ios/HybridScrollEdgeBar.swift +++ b/ios/HybridScrollEdgeBar.swift @@ -71,9 +71,6 @@ class HybridScrollEdgeBar: HybridRNScrollEdgeBarSpec { @objcMembers class ScrollEdgeBarContainerView: UIView { - - private static let bridgeWillReloadNotification = Notification.Name("RCTBridgeWillReloadNotification") - var estimatedTopBarHeight: CGFloat = 60 var estimatedBottomBarHeight: CGFloat = 60 var topBarOffset: CGFloat = 0 { @@ -97,31 +94,6 @@ class ScrollEdgeBarContainerView: UIView { private var detectedScrollView: UIScrollView? private var didAttachControllerView = false private var didNotifyOffsets: Bool = false - private var isBridgeReloading = false - - override init(frame: CGRect) { - super.init(frame: frame) - NotificationCenter.default.addObserver( - self, - selector: #selector(handleBridgeWillReload), - name: Self.bridgeWillReloadNotification, - object: nil - ) - } - - required init?(coder: NSCoder) { - super.init(coder: coder) - NotificationCenter.default.addObserver( - self, - selector: #selector(handleBridgeWillReload), - name: Self.bridgeWillReloadNotification, - object: nil - ) - } - - deinit { - NotificationCenter.default.removeObserver(self) - } override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { return false @@ -141,23 +113,9 @@ class ScrollEdgeBarContainerView: UIView { } } - override func willMove(toWindow newWindow: UIWindow?) { - super.willMove(toWindow: newWindow) - // Restore reparented views before Fabric unmounts them. - #if DEBUG - if newWindow == nil && window != nil { - return - } - #endif - if newWindow == nil && window != nil && !isBridgeReloading { - cleanupController() - } - } - override func didMoveToWindow() { super.didMoveToWindow() if window != nil { - isBridgeReloading = false parentViewController = findViewController() trySetup() } @@ -382,10 +340,6 @@ class ScrollEdgeBarContainerView: UIView { cleanupController() } - @objc private func handleBridgeWillReload() { - isBridgeReloading = true - } - private func cleanupController() { if #available(iOS 16.0, *), let controller = edgeBarController as? ScrollEdgeBarController { diff --git a/package.json b/package.json index 04b5ee7..61eb72c 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,9 @@ "example": "yarn workspace react-native-scroll-edge-bar-example", "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib", "prepare": "bob build", - "nitrogen": "nitrogen", + "nitrogen:generate": "nitrogen", + "nitrogen:patch": "node scripts/patch-nitrogen-scroll-edge-bar.js", + "nitrogen": "yarn nitrogen:generate ./src && yarn nitrogen:patch", "typecheck": "tsc", "lint": "eslint \"**/*.{js,ts,tsx}\"", "test": "jest", diff --git a/scripts/patch-nitrogen-scroll-edge-bar.js b/scripts/patch-nitrogen-scroll-edge-bar.js new file mode 100644 index 0000000..1482a74 --- /dev/null +++ b/scripts/patch-nitrogen-scroll-edge-bar.js @@ -0,0 +1,41 @@ +const fs = require('fs'); +const path = require('path'); + +const file = path.join( + __dirname, + '..', + 'nitrogen', + 'generated', + 'ios', + 'c++', + 'views', + 'HybridRNScrollEdgeBarComponent.mm' +); + +if (!fs.existsSync(file)) { + console.error(`Missing generated file: ${file}`); + process.exit(1); +} + +let source = fs.readFileSync(file, 'utf8'); + +const target = `- (void)invalidate\n{\n [[self scrollEdgeBarContainerView] prepareForFabricUnmount];\n [super invalidate];\n}`; +const patch = `${target}\n\n- (void)unmountChildComponentView:(UIView *)childComponentView\n index:(NSInteger)index\n{\n [[self scrollEdgeBarContainerView] prepareForFabricUnmount];\n [super unmountChildComponentView:childComponentView index:index];\n}`; + +if ( + source.includes( + '- (void)unmountChildComponentView:(UIView *)childComponentView' + ) +) { + console.log('Nitrogen patch already applied.'); + process.exit(0); +} + +if (!source.includes(target)) { + console.error('Could not find invalidate block to patch.'); + process.exit(1); +} + +source = source.replace(target, patch); +fs.writeFileSync(file, source); +console.log('Applied ScrollEdgeBar Nitrogen patch.');