golia-expo-utils 1.0.0 → 1.0.1

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.
@@ -7,6 +7,7 @@ import androidx.compose.runtime.mutableIntStateOf
7
7
  import androidx.compose.runtime.mutableStateOf
8
8
  import androidx.compose.ui.Modifier
9
9
  import androidx.compose.ui.platform.ComposeView
10
+ import androidx.compose.ui.platform.ViewCompositionStrategy
10
11
  import expo.modules.goliaexpoutils.Config
11
12
  import expo.modules.kotlin.AppContext
12
13
  import expo.modules.kotlin.viewevent.EventDispatcher
@@ -27,30 +28,11 @@ class ReactSegmentedControl(context: Context, appContext: AppContext) :
27
28
  val hapticEnabledState = mutableStateOf(true)
28
29
  val enabledState = mutableStateOf(true)
29
30
 
31
+ private var isContentSet = false
32
+
30
33
  private val composeView = ComposeView(context).apply {
31
34
  layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
32
- clipChildren = false
33
- clipToPadding = false
34
-
35
- setContent {
36
- SegmentedControl(
37
- items = itemsState.value,
38
- selectedIndex = selectedIndexState.intValue,
39
- onValueChange = { index ->
40
- selectedIndexState.intValue = index
41
- val title = itemsState.value.getOrNull(index)?.title ?: ""
42
- onValueChange(mapOf("value" to title, "index" to index))
43
- },
44
- modifier = Modifier.fillMaxSize(),
45
- activeColor = activeColorState.value,
46
- ctrlBackgroundColor = ctrlBgColorState.value,
47
- textColor = textColorState.value,
48
- autoWidth = autoWidthState.value,
49
- hapticEnabled = hapticEnabledState.value,
50
- enabled = enabledState.value,
51
- glassExpansion = Config.Common.Glass.DEFAULT_EXPANSION,
52
- )
53
- }
35
+ setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow)
54
36
  }
55
37
 
56
38
  init {
@@ -58,4 +40,30 @@ class ReactSegmentedControl(context: Context, appContext: AppContext) :
58
40
  clipToPadding = false
59
41
  addView(composeView)
60
42
  }
61
- }
43
+
44
+ override fun onAttachedToWindow() {
45
+ super.onAttachedToWindow()
46
+
47
+ if (!isContentSet) {
48
+ composeView.setContent {
49
+ SegmentedControl(
50
+ items = itemsState.value,
51
+ selectedIndex = selectedIndexState.intValue,
52
+ onValueChange = { index ->
53
+ selectedIndexState.intValue = index
54
+ val title = itemsState.value.getOrNull(index)?.title ?: ""
55
+ onValueChange(mapOf("value" to title, "index" to index))
56
+ },
57
+ modifier = Modifier.fillMaxSize(),
58
+ activeColor = activeColorState.value,
59
+ ctrlBackgroundColor = ctrlBgColorState.value,
60
+ textColor = textColorState.value,
61
+ autoWidth = autoWidthState.value,
62
+ hapticEnabled = hapticEnabledState.value,
63
+ enabled = enabledState.value,
64
+ glassExpansion = Config.Common.Glass.DEFAULT_EXPANSION,
65
+ )
66
+ }
67
+ }
68
+ }
69
+ }
@@ -53,29 +53,14 @@ class ReactWaterView(context: Context, appContext: AppContext) : ExpoView(contex
53
53
  private val onPressOut by EventDispatcher()
54
54
  private val commandChannel = Channel<WaterCommand>(Channel.BUFFERED)
55
55
  private val childContainer = FrameLayout(context).apply {
56
- layoutParams = ViewGroup.LayoutParams(
57
- LayoutParams.MATCH_PARENT,
58
- LayoutParams.MATCH_PARENT
59
- )
56
+ layoutParams = ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
60
57
  }
58
+
59
+ private var isContentSet = false
60
+
61
61
  private val composeView = ComposeView(context).apply {
62
- layoutParams = ViewGroup.LayoutParams(
63
- LayoutParams.MATCH_PARENT,
64
- LayoutParams.MATCH_PARENT
65
- )
66
- clipChildren = false
67
- clipToPadding = false
68
- setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindowOrReleasedFromPool)
69
- setContent {
70
- WaterViewEntry(
71
- childContainer = childContainer,
72
- props = props,
73
- commandFlow = commandChannel.receiveAsFlow(),
74
- onMoveDispatch = { x, y -> onMove(mapOf("x" to x, "y" to y)) },
75
- onPressInDispatch = { onPressIn(mapOf()) },
76
- onPressOutDispatch = { onPressOut(mapOf()) }
77
- )
78
- }
62
+ layoutParams = ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
63
+ setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow)
79
64
  }
80
65
 
81
66
  init {
@@ -84,6 +69,23 @@ class ReactWaterView(context: Context, appContext: AppContext) : ExpoView(contex
84
69
  addView(composeView)
85
70
  }
86
71
 
72
+ override fun onAttachedToWindow() {
73
+ super.onAttachedToWindow()
74
+
75
+ if (!isContentSet) {
76
+ composeView.setContent {
77
+ WaterViewEntry(
78
+ childContainer = childContainer,
79
+ props = props,
80
+ commandFlow = commandChannel.receiveAsFlow(),
81
+ onMoveDispatch = { x, y -> onMove(mapOf("x" to x, "y" to y)) },
82
+ onPressInDispatch = { onPressIn(mapOf()) },
83
+ onPressOutDispatch = { onPressOut(mapOf()) }
84
+ )
85
+ }
86
+ }
87
+ }
88
+
87
89
  override fun addView(child: View?, index: Int) {
88
90
  if (child == composeView) super.addView(child, index)
89
91
  else childContainer.addView(child)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "golia-expo-utils",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "expo utils provided by golia.jp",
5
5
  "main": "build/index.js",
6
6
  "homepage": "https://expo.golia.jp/golia-expo-utils",