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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import com.urbanairship.json.JsonValue
class ReactEmbeddedView(context: Context) : FrameLayout(context) {

private var renderedConfig: String? = null
private var sizeToContent: Boolean = false

/** Records whether the view measures its own content rather than filling its box. */
fun setSizeToContent(value: Boolean) {
this.sizeToContent = value
}

fun setConfig(config: String?) {
if (config == null || config == renderedConfig) {
Expand Down Expand Up @@ -56,4 +62,8 @@ class ReactEmbeddedView(context: Context) : FrameLayout(context) {
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY))
layout(left, top, right, bottom)
}

companion object {
const val EVENT_SIZE_CHANGE = "topAirshipEmbeddedViewSizeChange"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ReactEmbeddedViewManager : SimpleViewManager<ReactEmbeddedView>(),
override fun setProperty(view: ReactEmbeddedView, propName: String, value: Any?) {
when (propName) {
"config" -> setConfig(view, value as? String)
"sizeToContent" -> setSizeToContent(view, value as? Boolean ?: false)
else -> {}
}
}
Expand All @@ -44,11 +45,27 @@ class ReactEmbeddedViewManager : SimpleViewManager<ReactEmbeddedView>(),
return ReactEmbeddedView(reactContext)
}

override fun getExportedCustomBubblingEventTypeConstants(): MutableMap<String, Any> {
return mutableMapOf(
ReactEmbeddedView.EVENT_SIZE_CHANGE to mapOf(
"phasedRegistrationNames" to mapOf(
"bubbled" to "onSizeChange",
"captured" to "onSizeChangeCapture"
)
)
)
}

@ReactProp(name = "config")
override fun setConfig(view: ReactEmbeddedView, config: String?) {
view.setConfig(config)
}

@ReactProp(name = "sizeToContent")
override fun setSizeToContent(view: ReactEmbeddedView, sizeToContent: Boolean) {
view.setSizeToContent(sizeToContent)
}

companion object {
const val REACT_CLASS = "RNAirshipEmbeddedView"
}
Expand Down
28 changes: 28 additions & 0 deletions src/RNAirshipEmbeddedViewNativeComponent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
// @ts-ignore
import { codegenNativeComponent, type HostComponent, type ViewProps } from 'react-native';
import type {
BubblingEventHandler,
Double,
WithDefault,
// @ts-ignore
} from 'react-native/Libraries/Types/CodegenTypes';

type EmbeddedSizeChangeEvent = Readonly<{
/**
* The content's measured height, in points.
*/
height: Double;
}>;

interface NativeProps extends ViewProps {
config: string;

/**
* Whether the view measures its own content and reports the height, rather
* than filling the box it is given.
*/
sizeToContent?: WithDefault<boolean, false>;

/**
* Called whenever the measured content height changes. Only emitted while
* `sizeToContent` is set.
*/
onSizeChange?: BubblingEventHandler<
EmbeddedSizeChangeEvent,
'topAirshipEmbeddedViewSizeChange'
>;
}

export default codegenNativeComponent<NativeProps>('RNAirshipEmbeddedView') as HostComponent<NativeProps>;
Loading