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
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
FBLazyVector: 7c1d69992204c5ec452eeefa4a24b0ff311709c8
hermes-engine: 16e781d7fca74c8bb3ca59b99527d9633ee9ee36
hermes-engine: b69aade2dcf59e8c2203c748ca79c7fa4c875053
NitroModules: fb232c72f7f287543f0c6c214c2a75dce8de8cf3
NitroTest: 732039c97fdd73f8d95887475ca4a8713696cc06
NitroTestExternal: eaec60657bfaa38eb3e4eb6e996548221606e428
Expand All @@ -2229,7 +2229,7 @@ SPEC CHECKSUMS:
React: f6f8fc5c01e77349cdfaf49102bcb928ac31d8ed
React-callinvoker: 3e62a849bda1522c6422309c02f5dc3210bc5359
React-Core: 0b765bc7c2b83dff178c2b03ed8a0390df26f18c
React-Core-prebuilt: 88810feb58457484bff17e9e91a15453407d745a
React-Core-prebuilt: 1ed3b91c7035f715bf741f1b8a2c87e94d126d38
React-CoreModules: 55b932564ba696301cb683a86385be6a6f137e57
React-cxxreact: 5bfb95256fde56cc0f9ce425f38cfaa085e71ad2
React-debug: f9dda2791d3ebe2078bc6102641edab77917efb7
Expand Down Expand Up @@ -2292,7 +2292,7 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: 23e2bca1661f8781e55fcc05a151fc1df97bc1fb
ReactCodegen: c049d7e966ed24be56d8e21cb1b8880316975e76
ReactCommon: 89ccc6cb100ca5a0303b46483037ef8f3e06e2e0
ReactNativeDependencies: 1a7e3c3ffa57533d8118dd9bc01790ffa9e02a3b
ReactNativeDependencies: 69de62c8a59d21e7b6af8bdfb62b61e798f65351
RNScreens: dd61bc3a3e6f6901ad833efa411917d44827cf51
Yoga: 21f482cbc18b56cdc477cd3a0c5b8c2c83ac27ce

Expand Down
5 changes: 5 additions & 0 deletions packages/nitrogen/src/syntax/swift/SwiftHybridObjectBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public final func maybePrepareForRecycle() {
guard let recyclable = __implementation as? any RecyclableView else { return }
recyclable.prepareForRecycle()
}
`.trim(),
`
public final func onDropView() {
__implementation.onDropView()
}
`.trim()
)
}
Expand Down
14 changes: 12 additions & 2 deletions packages/nitrogen/src/views/kotlin/KotlinHybridViewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class ${manager}: SimpleViewManager<View>() {
}

override fun updateState(view: View, props: ReactStylesDiffMap, stateWrapper: StateWrapper): Any? {
val hybridView = view.getTag(associated_hybrid_view_tag) as? ${viewImplementation}
val hybridView = getHybridView(view)
?: throw Error("Couldn't find view $view in local views table!")

// 1. Update each prop individually
Expand All @@ -87,9 +87,15 @@ public class ${manager}: SimpleViewManager<View>() {
return super.updateState(view, props, stateWrapper)
}

override fun onDropViewInstance(view: View) {
val hybridView = getHybridView(view)
hybridView?.onDropView()
return super.onDropViewInstance(view)
}

protected override fun prepareToRecycleView(reactContext: ThemedReactContext, view: View): View? {
super.prepareToRecycleView(reactContext, view)
val hybridView = view.getTag(associated_hybrid_view_tag) as? ${viewImplementation}
val hybridView = getHybridView(view)
?: return null

@Suppress("USELESS_IS_CHECK")
Expand All @@ -103,6 +109,10 @@ public class ${manager}: SimpleViewManager<View>() {
return null
}
}

private fun getHybridView(view: View): ${viewImplementation}? {
return view.getTag(associated_hybrid_view_tag) as? ${viewImplementation}
}
}
`.trim()

Expand Down
6 changes: 6 additions & 0 deletions packages/nitrogen/src/views/swift/SwiftHybridViewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ using namespace ${namespace}::views;
swiftPart.maybePrepareForRecycle();
}

- (void)invalidate {
${swiftNamespace}::${HybridTSpecCxx}& swiftPart = _hybridView->getSwiftPart();
swiftPart.onDropView();
[super invalidate];
}

@end
`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ abstract class HybridView : HybridObject() {
* React props are updated in a single batch/transaction.
*/
open fun afterUpdate() { /* noop */ }

/**
* Called when the [HybridView] is about
* to be dropped and unmounted.
* This is a good place to clean up view-related
* resources.
*/
open fun onDropView() { /* noop */ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@
* React props are updated in a single batch/transaction.
*/
func afterUpdate()

/**
* Called when the `HybridView` is about
* to be dropped and unmounted.
* This is a good place to clean up view-related
* resources.
*/
func onDropView()
}

extension HybridView {
public func beforeUpdate() { /* noop */ }
public func afterUpdate() { /* noop */ }
public func onDropView() { /* noop */ }
}

extension HybridView {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.margelo.nitro.test

import android.graphics.Color
import android.util.Log
import android.view.View
import androidx.annotation.Keep
import com.facebook.proguard.annotations.DoNotStrip
Expand All @@ -27,6 +28,10 @@ class HybridRecyclableTestView(
}
}

override fun onDropView() {
Log.i(TAG, "View dropped!")
}

// Recycling conformance
override fun prepareForRecycle() {
view.setBackgroundColor(Color.YELLOW)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class HybridRecyclableTestView: HybridRecyclableTestViewSpec, RecyclableView {
}
}

func onDropView() {
print("View dropped!")
}

// Recycling conformance
func prepareForRecycle() {
view.backgroundColor = .yellow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class HybridRecyclableTestViewManager: SimpleViewManager<View>() {
}

override fun updateState(view: View, props: ReactStylesDiffMap, stateWrapper: StateWrapper): Any? {
val hybridView = view.getTag(associated_hybrid_view_tag) as? HybridRecyclableTestView
val hybridView = getHybridView(view)
?: throw Error("Couldn't find view $view in local views table!")

// 1. Update each prop individually
Expand All @@ -51,9 +51,15 @@ public class HybridRecyclableTestViewManager: SimpleViewManager<View>() {
return super.updateState(view, props, stateWrapper)
}

override fun onDropViewInstance(view: View) {
val hybridView = getHybridView(view)
hybridView?.onDropView()
return super.onDropViewInstance(view)
}

protected override fun prepareToRecycleView(reactContext: ThemedReactContext, view: View): View? {
super.prepareToRecycleView(reactContext, view)
val hybridView = view.getTag(associated_hybrid_view_tag) as? HybridRecyclableTestView
val hybridView = getHybridView(view)
?: return null

@Suppress("USELESS_IS_CHECK")
Expand All @@ -67,4 +73,8 @@ public class HybridRecyclableTestViewManager: SimpleViewManager<View>() {
return null
}
}

private fun getHybridView(view: View): HybridRecyclableTestView? {
return view.getTag(associated_hybrid_view_tag) as? HybridRecyclableTestView
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class HybridTestViewManager: SimpleViewManager<View>() {
}

override fun updateState(view: View, props: ReactStylesDiffMap, stateWrapper: StateWrapper): Any? {
val hybridView = view.getTag(associated_hybrid_view_tag) as? HybridTestView
val hybridView = getHybridView(view)
?: throw Error("Couldn't find view $view in local views table!")

// 1. Update each prop individually
Expand All @@ -51,9 +51,15 @@ public class HybridTestViewManager: SimpleViewManager<View>() {
return super.updateState(view, props, stateWrapper)
}

override fun onDropViewInstance(view: View) {
val hybridView = getHybridView(view)
hybridView?.onDropView()
return super.onDropViewInstance(view)
}

protected override fun prepareToRecycleView(reactContext: ThemedReactContext, view: View): View? {
super.prepareToRecycleView(reactContext, view)
val hybridView = view.getTag(associated_hybrid_view_tag) as? HybridTestView
val hybridView = getHybridView(view)
?: return null

@Suppress("USELESS_IS_CHECK")
Expand All @@ -67,4 +73,8 @@ public class HybridTestViewManager: SimpleViewManager<View>() {
return null
}
}

private fun getHybridView(view: View): HybridTestView? {
return view.getTag(associated_hybrid_view_tag) as? HybridTestView
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,10 @@ - (void)prepareForRecycle {
swiftPart.maybePrepareForRecycle();
}

- (void)invalidate {
NitroTest::HybridRecyclableTestViewSpec_cxx& swiftPart = _hybridView->getSwiftPart();
swiftPart.onDropView();
[super invalidate];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,10 @@ - (void)prepareForRecycle {
swiftPart.maybePrepareForRecycle();
}

- (void)invalidate {
NitroTest::HybridTestViewSpec_cxx& swiftPart = _hybridView->getSwiftPart();
swiftPart.onDropView();
[super invalidate];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,8 @@ open class HybridRecyclableTestViewSpec_cxx {
guard let recyclable = __implementation as? any RecyclableView else { return }
recyclable.prepareForRecycle()
}

public final func onDropView() {
__implementation.onDropView()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,8 @@ open class HybridTestViewSpec_cxx {
guard let recyclable = __implementation as? any RecyclableView else { return }
recyclable.prepareForRecycle()
}

public final func onDropView() {
__implementation.onDropView()
}
}
Loading