react-native-controlled-input 0.12.0 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/android/build.gradle
CHANGED
|
@@ -88,5 +88,6 @@ dependencies {
|
|
|
88
88
|
implementation 'androidx.compose.ui:ui-tooling-preview'
|
|
89
89
|
implementation 'androidx.compose.material3:material3'
|
|
90
90
|
implementation 'androidx.activity:activity-compose:1.12.2'
|
|
91
|
+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.7'
|
|
91
92
|
debugImplementation 'androidx.compose.ui:ui-tooling'
|
|
92
93
|
}
|
|
@@ -11,11 +11,16 @@ import androidx.compose.runtime.remember
|
|
|
11
11
|
import androidx.compose.ui.focus.FocusRequester
|
|
12
12
|
import androidx.compose.ui.platform.ComposeView
|
|
13
13
|
import androidx.compose.ui.platform.LocalFocusManager
|
|
14
|
+
import androidx.compose.ui.platform.ViewCompositionStrategy
|
|
15
|
+
import androidx.lifecycle.Lifecycle
|
|
16
|
+
import androidx.lifecycle.LifecycleOwner
|
|
17
|
+
import androidx.lifecycle.LifecycleRegistry
|
|
18
|
+
import androidx.lifecycle.setViewTreeLifecycleOwner
|
|
14
19
|
import com.facebook.react.bridge.ReactContext
|
|
15
20
|
import com.facebook.react.uimanager.UIManagerHelper
|
|
16
21
|
import kotlinx.coroutines.flow.MutableStateFlow
|
|
17
22
|
|
|
18
|
-
class ControlledInputView : LinearLayout {
|
|
23
|
+
class ControlledInputView : LinearLayout, LifecycleOwner {
|
|
19
24
|
constructor(context: Context) : super(context) {
|
|
20
25
|
configureComponent(context)
|
|
21
26
|
}
|
|
@@ -32,10 +37,24 @@ class ControlledInputView : LinearLayout {
|
|
|
32
37
|
configureComponent(context)
|
|
33
38
|
}
|
|
34
39
|
|
|
40
|
+
private val lifecycleRegistry = LifecycleRegistry(this)
|
|
41
|
+
override val lifecycle: Lifecycle get() = lifecycleRegistry
|
|
42
|
+
|
|
35
43
|
internal lateinit var viewModel: JetpackComposeViewModel
|
|
36
44
|
private val blurSignal = MutableStateFlow(0)
|
|
37
45
|
private val focusSignal = MutableStateFlow(0)
|
|
38
46
|
|
|
47
|
+
override fun onAttachedToWindow() {
|
|
48
|
+
setViewTreeLifecycleOwner(this)
|
|
49
|
+
lifecycleRegistry.currentState = Lifecycle.State.RESUMED
|
|
50
|
+
super.onAttachedToWindow()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override fun onDetachedFromWindow() {
|
|
54
|
+
super.onDetachedFromWindow()
|
|
55
|
+
lifecycleRegistry.currentState = Lifecycle.State.CREATED
|
|
56
|
+
}
|
|
57
|
+
|
|
39
58
|
fun blur() {
|
|
40
59
|
// триггерим compose снять фокус
|
|
41
60
|
blurSignal.value = blurSignal.value + 1
|
|
@@ -68,6 +87,8 @@ class ControlledInputView : LinearLayout {
|
|
|
68
87
|
)
|
|
69
88
|
it.setBackgroundColor(android.graphics.Color.TRANSPARENT)
|
|
70
89
|
|
|
90
|
+
it.setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
|
91
|
+
|
|
71
92
|
viewModel = JetpackComposeViewModel()
|
|
72
93
|
|
|
73
94
|
it.setContent {
|
package/package.json
CHANGED