To create a custom widget that uses other Beagle components, just implement the SingleChildComponent
interface when there is only one child component, or MultiChildComponent
for the widget that uses several other components.
SingleChildComponent
, or MultiChildComponent
, never both at the same time.Custom widgets that render a single Beagle component must implement the SingleChildComponent
interface.
SingleChildComponent
With the custom widget created, add the SingleChildComponent
interface.
@RegisterWidget
class CustomChildWidget(
val name: String,
val phone: String,
val age: Int
): WidgetView(), SingleChildComponent {
override fun buildView(rootView: RootView): View {
TODO("Not yet implemented")
}
}
child
propertyAfter adding the SingleChildComponent
interface to the widget, override the child
property.
@RegisterWidget
class CustomChildWidget(
val name: String,
val phone: String,
val age: Int,
override val child: ServerDrivenComponent
): WidgetView(), SingleChildComponent {
override fun buildView(rootView: RootView): View {
TODO("Not yet implemented")
}
}
To use the view generated from the child
component, just consider it as a ViewConvertable
and call the buildView
method.
@RegisterWidget
class CustomChildWidget(
val name: String,
val phone: String,
val age: Int,
override val child: ServerDrivenComponent
): WidgetView(), SingleChildComponent {
override fun buildView(rootView: RootView): View {
val builtChild = (child as ViewConvertable).buildView(rootView)
}
}
Custom widgets that render one or more Beagle components must implement the MultiChildComponent
interface.
MultiChildComponent
With the custom widget created, add the MultiChildComponent
interface.
@RegisterWidget
class CustomChildWidget(
val name: String,
val phone: String,
val age: Int
): WidgetView(), MultiChildComponent {
override fun buildView(rootView: RootView): View {
TODO("Not yet implemented")
}
}
children
propertyAfter adding the MultiChildComponent
interface to the widget, override the children
property.
@RegisterWidget
class CustomChildWidget(
val name: String,
val phone: String,
val age: Int,
override val children: List<ServerDrivenComponent>
): WidgetView(), SingleChildComponent {
override fun buildView(rootView: RootView): View {
TODO("Not yet implemented")
}
}
To use the view generated from the children
component, just consider each one as ViewConvertable
and call their buildView
method.
@RegisterWidget
class CustomChildWidget(
val name: String,
val phone: String,
val age: Int,
override val children: List<ServerDrivenComponent>
): WidgetView(), SingleChildComponent {
override fun buildView(rootView: RootView): View {
children.forEach { child ->
val builtChild = (child as ViewConvertable).buildView(rootView)
}
}
}
It’s done! Your component now uses other Beagle components!
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.