mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-28 20:40:13 +02:00
feat: composer utils
This commit is contained in:
parent
342bc7c68b
commit
c1d3e0736a
@ -17,6 +17,10 @@ class SnapClassCache (
|
||||
val feedEntry by lazy { findClass("com.snapchat.client.messaging.FeedEntry") }
|
||||
val conversation by lazy { findClass("com.snapchat.client.messaging.Conversation") }
|
||||
val feedManager by lazy { findClass("com.snapchat.client.messaging.FeedManager\$CppProxy") }
|
||||
val nativeBridge by lazy { findClass("com.snapchat.client.composer.NativeBridge") }
|
||||
val composerView by lazy { findClass("com.snap.composer.views.ComposerView") }
|
||||
val composerAction by lazy { findClass("com.snap.composer.actions.ComposerAction") }
|
||||
val composerFunctionActionAdapter by lazy { findClass("com.snap.composer.callable.ComposerFunctionActionAdapter") }
|
||||
|
||||
private fun findClass(className: String): Class<*> {
|
||||
return try {
|
||||
|
@ -19,9 +19,11 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Switch
|
||||
import android.widget.TextView
|
||||
import me.rhunk.snapenhance.core.SnapEnhance
|
||||
import me.rhunk.snapenhance.core.util.ktx.getDimens
|
||||
import me.rhunk.snapenhance.core.util.ktx.getDimensFloat
|
||||
import me.rhunk.snapenhance.core.util.ktx.getIdentifier
|
||||
import me.rhunk.snapenhance.core.wrapper.impl.composer.ComposerViewNode
|
||||
import kotlin.random.Random
|
||||
|
||||
fun View.applyTheme(componentWidth: Int? = null, hasRadius: Boolean = false, isAmoled: Boolean = true) {
|
||||
@ -91,6 +93,16 @@ fun View.iterateParent(predicate: (View) -> Boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
fun View.getComposerViewNode(): ComposerViewNode? {
|
||||
if (!this::class.java.isAssignableFrom(SnapEnhance.classCache.composerView)) return null
|
||||
val composerViewNode = this::class.java.methods.firstOrNull {
|
||||
it.name == "getComposerViewNode"
|
||||
}?.invoke(this) ?: return null
|
||||
|
||||
return ComposerViewNode(composerViewNode::class.java.methods.firstOrNull {
|
||||
it.name == "getNativeHandle"
|
||||
}?.invoke(composerViewNode) as? Long ?: return null)
|
||||
}
|
||||
|
||||
object ViewAppearanceHelper {
|
||||
private fun createRoundedBackground(color: Int, radius: Float, hasRadius: Boolean): Drawable {
|
||||
|
@ -0,0 +1,50 @@
|
||||
package me.rhunk.snapenhance.core.wrapper.impl.composer
|
||||
|
||||
import me.rhunk.snapenhance.core.SnapEnhance
|
||||
import me.rhunk.snapenhance.core.wrapper.AbstractWrapper
|
||||
import java.lang.reflect.Proxy
|
||||
|
||||
fun createComposerFunction(block: (args: Array<*>) -> Any?): Any {
|
||||
return SnapEnhance.classCache.composerFunctionActionAdapter.constructors.first().newInstance(
|
||||
Proxy.newProxyInstance(
|
||||
SnapEnhance.classCache.composerAction.classLoader,
|
||||
arrayOf(SnapEnhance.classCache.composerAction),
|
||||
) { _, _, args ->
|
||||
block(args?.get(0) as Array<*>)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
class ComposerViewNode(obj: Long) : AbstractWrapper(obj) {
|
||||
fun getAttribute(name: String): Any? {
|
||||
return SnapEnhance.classCache.nativeBridge.methods.firstOrNull {
|
||||
it.name == "getValueForAttribute"
|
||||
}?.invoke(null, instanceNonNull(), name)
|
||||
}
|
||||
|
||||
fun setAttribute(name: String, value: Any) {
|
||||
SnapEnhance.classCache.nativeBridge.methods.firstOrNull {
|
||||
it.name == "setValueForAttribute"
|
||||
}?.invoke(null, instanceNonNull(), name, value, false)
|
||||
}
|
||||
|
||||
fun getChildren(): List<ComposerViewNode> {
|
||||
return ((SnapEnhance.classCache.nativeBridge.methods.firstOrNull {
|
||||
it.name == "getRetainedViewNodeChildren"
|
||||
}?.invoke(null, instanceNonNull(), 1))!! as? LongArray)?.map {
|
||||
ComposerViewNode(it)
|
||||
} ?: emptyList()
|
||||
}
|
||||
|
||||
fun getClassName(): String {
|
||||
return SnapEnhance.classCache.nativeBridge.methods.firstOrNull {
|
||||
it.name == "getViewClassName"
|
||||
}?.invoke(null, instanceNonNull()).toString()
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return SnapEnhance.classCache.nativeBridge.methods.firstOrNull {
|
||||
it.name == "getViewNodeDebugDescription"
|
||||
}?.invoke(null, instanceNonNull()).toString()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user