Skip to content

Commit

Permalink
Convert ReactModalHostManager to Kotlin (#43844)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43844

This converts the last class inside `com.facebook.react.views.modal` to Kotlin

Changelog:
[Internal] [Changed] - Convert ReactModalHostManager to Kotlin

Reviewed By: javache

Differential Revision: D55739386
  • Loading branch information
cortinico authored and facebook-github-bot committed Apr 5, 2024
1 parent 7a50239 commit 9e03853
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 182 deletions.
15 changes: 8 additions & 7 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -6209,21 +6209,19 @@ public class com/facebook/react/views/modal/ModalHostShadowNode$$PropsSetter : c
public fun setProperty (Lcom/facebook/react/views/modal/ModalHostShadowNode;Ljava/lang/String;Ljava/lang/Object;)V
}

public class com/facebook/react/views/modal/ReactModalHostManager : com/facebook/react/uimanager/ViewGroupManager, com/facebook/react/viewmanagers/ModalHostViewManagerInterface {
public final class com/facebook/react/views/modal/ReactModalHostManager : com/facebook/react/uimanager/ViewGroupManager, com/facebook/react/viewmanagers/ModalHostViewManagerInterface {
public static final field Companion Lcom/facebook/react/views/modal/ReactModalHostManager$Companion;
public static final field REACT_CLASS Ljava/lang/String;
public fun <init> ()V
protected synthetic fun addEventEmitters (Lcom/facebook/react/uimanager/ThemedReactContext;Landroid/view/View;)V
protected fun addEventEmitters (Lcom/facebook/react/uimanager/ThemedReactContext;Lcom/facebook/react/views/modal/ReactModalHostView;)V
public synthetic fun addEventEmitters (Lcom/facebook/react/uimanager/ThemedReactContext;Landroid/view/View;)V
public fun createShadowNodeInstance ()Lcom/facebook/react/uimanager/LayoutShadowNode;
public synthetic fun createShadowNodeInstance ()Lcom/facebook/react/uimanager/ReactShadowNode;
protected synthetic fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Landroid/view/View;
protected fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Lcom/facebook/react/views/modal/ReactModalHostView;
public synthetic fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Landroid/view/View;
public fun getDelegate ()Lcom/facebook/react/uimanager/ViewManagerDelegate;
public fun getExportedCustomDirectEventTypeConstants ()Ljava/util/Map;
public fun getName ()Ljava/lang/String;
public fun getShadowNodeClass ()Ljava/lang/Class;
protected synthetic fun onAfterUpdateTransaction (Landroid/view/View;)V
protected fun onAfterUpdateTransaction (Lcom/facebook/react/views/modal/ReactModalHostView;)V
public synthetic fun onAfterUpdateTransaction (Landroid/view/View;)V
public synthetic fun onDropViewInstance (Landroid/view/View;)V
public fun onDropViewInstance (Lcom/facebook/react/views/modal/ReactModalHostView;)V
public synthetic fun setAnimated (Landroid/view/View;Z)V
Expand Down Expand Up @@ -6255,6 +6253,9 @@ public class com/facebook/react/views/modal/ReactModalHostManager$$PropsSetter :
public fun setProperty (Lcom/facebook/react/views/modal/ReactModalHostManager;Lcom/facebook/react/views/modal/ReactModalHostView;Ljava/lang/String;Ljava/lang/Object;)V
}

public final class com/facebook/react/views/modal/ReactModalHostManager$Companion {
}

public final class com/facebook/react/views/modal/ReactModalHostView : android/view/ViewGroup, com/facebook/react/bridge/LifecycleEventListener {
public fun <init> (Lcom/facebook/react/uimanager/ThemedReactContext;)V
public fun addChildrenForAccessibility (Ljava/util/ArrayList;)V
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.views.modal

import android.content.DialogInterface.OnShowListener
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.common.MapBuilder
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.LayoutShadowNode
import com.facebook.react.uimanager.ReactStylesDiffMap
import com.facebook.react.uimanager.StateWrapper
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.viewmanagers.ModalHostViewManagerDelegate
import com.facebook.react.viewmanagers.ModalHostViewManagerInterface
import com.facebook.react.views.modal.ModalHostHelper.getModalHostSize
import com.facebook.react.views.modal.ReactModalHostView.OnRequestCloseListener

/** View manager for [ReactModalHostView] components. */
@ReactModule(name = ReactModalHostManager.REACT_CLASS)
public class ReactModalHostManager :
ViewGroupManager<ReactModalHostView>(), ModalHostViewManagerInterface<ReactModalHostView> {
private val delegate: ViewManagerDelegate<ReactModalHostView> = ModalHostViewManagerDelegate(this)

public override fun getName(): String = REACT_CLASS

protected override fun createViewInstance(reactContext: ThemedReactContext): ReactModalHostView =
ReactModalHostView(reactContext)

public override fun createShadowNodeInstance(): LayoutShadowNode = ModalHostShadowNode()

public override fun getShadowNodeClass(): Class<out LayoutShadowNode> =
ModalHostShadowNode::class.java

public override fun onDropViewInstance(view: ReactModalHostView) {
super.onDropViewInstance(view)
view.onDropInstance()
}

@ReactProp(name = "animationType")
public override fun setAnimationType(view: ReactModalHostView, animationType: String?) {
if (animationType != null) {
view.animationType = animationType
}
}

@ReactProp(name = "transparent")
public override fun setTransparent(view: ReactModalHostView, transparent: Boolean) {
view.transparent = transparent
}

@ReactProp(name = "statusBarTranslucent")
public override fun setStatusBarTranslucent(
view: ReactModalHostView,
statusBarTranslucent: Boolean
) {
view.statusBarTranslucent = statusBarTranslucent
}

@ReactProp(name = "hardwareAccelerated")
public override fun setHardwareAccelerated(
view: ReactModalHostView,
hardwareAccelerated: Boolean
) {
view.hardwareAccelerated = hardwareAccelerated
}

@ReactProp(name = "visible")
public override fun setVisible(view: ReactModalHostView, visible: Boolean) {
// iOS only
}

@ReactProp(name = "presentationStyle")
public override fun setPresentationStyle(view: ReactModalHostView, value: String?): Unit = Unit

@ReactProp(name = "animated")
public override fun setAnimated(view: ReactModalHostView, value: Boolean): Unit = Unit

@ReactProp(name = "supportedOrientations")
public override fun setSupportedOrientations(
view: ReactModalHostView,
value: ReadableArray?
): Unit = Unit

@ReactProp(name = "identifier")
public override fun setIdentifier(view: ReactModalHostView, value: Int): Unit = Unit

protected override fun addEventEmitters(
reactContext: ThemedReactContext,
view: ReactModalHostView
) {
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, view.id)
if (dispatcher != null) {
view.onRequestCloseListener = OnRequestCloseListener {
dispatcher.dispatchEvent(
RequestCloseEvent(UIManagerHelper.getSurfaceId(reactContext), view.id))
}
view.onShowListener = OnShowListener {
dispatcher.dispatchEvent(ShowEvent(UIManagerHelper.getSurfaceId(reactContext), view.id))
}
view.eventDispatcher = dispatcher
}
}

public override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> =
(super.getExportedCustomDirectEventTypeConstants() ?: mutableMapOf()).apply {
putAll(
MapBuilder.builder<String, Any>()
.put(
RequestCloseEvent.EVENT_NAME,
MapBuilder.of("registrationName", "onRequestClose"))
.put(ShowEvent.EVENT_NAME, MapBuilder.of("registrationName", "onShow")) // iOS only
.put("topDismiss", MapBuilder.of("registrationName", "onDismiss")) // iOS only
.put(
"topOrientationChange",
MapBuilder.of("registrationName", "onOrientationChange"))
.build())
}

protected override fun onAfterUpdateTransaction(view: ReactModalHostView) {
super.onAfterUpdateTransaction(view)
view.showOrUpdate()
}

public override fun updateState(
view: ReactModalHostView,
props: ReactStylesDiffMap,
stateWrapper: StateWrapper
): Any? {
view.stateWrapper = stateWrapper
val modalSize = getModalHostSize(view.context)
view.updateState(modalSize.x, modalSize.y)
return null
}

public override fun getDelegate(): ViewManagerDelegate<ReactModalHostView> = delegate

public companion object {
public const val REACT_CLASS: String = "RCTModalHostView"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public class ReactModalHostView(context: ThemedReactContext) :
// This listener is called when the user presses KeyEvent.KEYCODE_BACK
// An event is then passed to JS which can either close or not close the Modal by setting the
// visible property
public interface OnRequestCloseListener {
public fun interface OnRequestCloseListener {
public fun onRequestClose(dialog: DialogInterface?)
}

Expand Down

0 comments on commit 9e03853

Please sign in to comment.