feat: add LP generic function in ViewGroup

This commit is contained in:
2025-08-23 21:22:05 +08:00
parent 51a59b672c
commit 0529d6a2b6
3 changed files with 15 additions and 3 deletions

View File

@@ -219,7 +219,7 @@ Or, use in a custom `View`.
class CustomView(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {
init {
addView {
addView<FrameLayout.LayoutParams> {
TextView {
text = "Hello, World!"
textSize = 16f

View File

@@ -217,7 +217,7 @@ root.addView {
class CustomView(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {
init {
addView {
addView<FrameLayout.LayoutParams> {
TextView {
text = "Hello, World!"
textSize = 16f

View File

@@ -30,6 +30,18 @@ import com.highcapable.hikage.core.base.HikageFactoryBuilder
import com.highcapable.hikage.core.base.HikagePerformer
import com.highcapable.hikage.core.base.Hikageable
/**
* @see ViewGroup.addView
* @see Hikageable
* @return [Hikage]
*/
@JvmName("addViewTyped")
inline fun <reified LP : ViewGroup.LayoutParams> ViewGroup.addView(
index: Int = -1,
factory: HikageFactoryBuilder.() -> Unit = {},
performer: HikagePerformer<LP>
) = Hikageable<LP>(context = context, factory = factory, performer = performer).apply { addView(root, index) }
/**
* @see ViewGroup.addView
* @see Hikageable
@@ -39,7 +51,7 @@ inline fun ViewGroup.addView(
index: Int = -1,
factory: HikageFactoryBuilder.() -> Unit = {},
performer: HikagePerformer<ViewGroup.LayoutParams>
) = Hikageable(context = context, factory = factory, performer = performer).apply { addView(root, index) }
) = addView<ViewGroup.LayoutParams>(index, factory, performer)
/**
* @see ViewGroup.addView