|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +package com.facebook.react.views.text.frescosupport |
| 9 | + |
| 10 | +import android.view.View |
| 11 | +import com.facebook.drawee.backends.pipeline.Fresco |
| 12 | +import com.facebook.drawee.controller.AbstractDraweeControllerBuilder |
| 13 | +import com.facebook.react.module.annotations.ReactModule |
| 14 | +import com.facebook.react.uimanager.BaseViewManager |
| 15 | +import com.facebook.react.uimanager.ThemedReactContext |
| 16 | + |
| 17 | +/** |
| 18 | + * Manages Images embedded in Text nodes using Fresco. Since they are used only as a virtual nodes |
| 19 | + * any type of native view operation will throw an [IllegalStateException]. |
| 20 | + */ |
| 21 | +@ReactModule(name = FrescoBasedReactTextInlineImageViewManager.REACT_CLASS) |
| 22 | +internal class FrescoBasedReactTextInlineImageViewManager |
| 23 | +@JvmOverloads |
| 24 | +constructor( |
| 25 | + private val draweeControllerBuilder: |
| 26 | + @JvmSuppressWildcards |
| 27 | + AbstractDraweeControllerBuilder<*, *, *, *>? = |
| 28 | + null, |
| 29 | + private val callerContext: Any? = null |
| 30 | +) : BaseViewManager<View, FrescoBasedReactTextInlineImageShadowNode>() { |
| 31 | + |
| 32 | + override fun getName(): String = REACT_CLASS |
| 33 | + |
| 34 | + public override fun createViewInstance(context: ThemedReactContext): View { |
| 35 | + throw IllegalStateException("RCTTextInlineImage doesn't map into a native view") |
| 36 | + } |
| 37 | + |
| 38 | + override fun createShadowNodeInstance(): FrescoBasedReactTextInlineImageShadowNode = |
| 39 | + FrescoBasedReactTextInlineImageShadowNode( |
| 40 | + draweeControllerBuilder ?: Fresco.newDraweeControllerBuilder(), callerContext) |
| 41 | + |
| 42 | + override fun getShadowNodeClass(): Class<FrescoBasedReactTextInlineImageShadowNode> = |
| 43 | + FrescoBasedReactTextInlineImageShadowNode::class.java |
| 44 | + |
| 45 | + override fun updateExtraData(root: View, extraData: Any) = Unit |
| 46 | + |
| 47 | + public companion object { |
| 48 | + public const val REACT_CLASS: String = "RCTTextInlineImage" |
| 49 | + } |
| 50 | +} |
0 commit comments