Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export default function App() {
title: 'Transition Showcase',
headerShadowVisible: false,
headerTransparent: true,
headerLargeTitleEnabled: true,
headerBackButtonDisplayMode: 'minimal',
headerTintColor: DynamicColorIOS({
light: 'black',
Expand Down
1 change: 1 addition & 0 deletions example/src/screens/CalendarScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export function CalendarScreen() {
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
},
topBar: {
paddingHorizontal: 0,
Expand Down
46 changes: 0 additions & 46 deletions ios/HybridScrollEdgeBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 41 additions & 0 deletions scripts/patch-nitrogen-scroll-edge-bar.js
Original file line number Diff line number Diff line change
@@ -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<RCTComponentViewProtocol> *)childComponentView\n index:(NSInteger)index\n{\n [[self scrollEdgeBarContainerView] prepareForFabricUnmount];\n [super unmountChildComponentView:childComponentView index:index];\n}`;

if (
source.includes(
'- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)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.');
Loading