Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 86fbed8

Browse files
committed
fix(uidesigner): do not keep a reference to ViewInfoSheet instance
1 parent 1133347 commit 86fbed8

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

uidesigner/src/main/java/com/itsaky/androidide/uidesigner/fragments/DesignerWorkspaceFragment.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ class DesignerWorkspaceFragment : BaseFragment() {
5656
private var binding: FragmentDesignerWorkspaceBinding? = null
5757
internal val viewModel by viewModels<WorkspaceViewModel>(ownerProducer = { requireActivity() })
5858

59-
private var _viewInfo: ViewInfoSheet? = null
6059
private val touchSlop by lazy { get(requireContext()).scaledTouchSlop }
6160

62-
private val viewInfo: ViewInfoSheet
63-
get() = this._viewInfo ?: ViewInfoSheet().also { _viewInfo = it }
64-
6561
internal var isInflating = false
6662
internal val workspaceView by lazy {
6763
UiViewGroup(LayoutFile(File(""), ""), LinearLayout::class.qualifiedName!!, binding!!.workspace)
@@ -87,6 +83,7 @@ class DesignerWorkspaceFragment : BaseFragment() {
8783
private val attrHandler by lazy { WorkspaceViewAttrHandler() }
8884

8985
companion object {
86+
9087
const val DRAGGING_WIDGET = "DRAGGING_WIDGET"
9188
const val DRAGGING_WIDGET_MIME = "androidide/uidesigner_widget"
9289
const val HIERARCHY_CHANGE_TRANSITION_DURATION = 100L
@@ -145,10 +142,13 @@ class DesignerWorkspaceFragment : BaseFragment() {
145142
override fun onDestroyView() {
146143
super.onDestroyView()
147144
this.binding = null
148-
this._viewInfo?.dismiss()
149-
this._viewInfo = null
150145
this.hierarchyHandler.release()
151146
this.attrHandler.release()
147+
148+
if (!childFragmentManager.isDestroyed) {
149+
val viewInfo = childFragmentManager.findFragmentByTag(ViewInfoSheet.TAG) as? ViewInfoSheet?
150+
viewInfo?.dismiss()
151+
}
152152
}
153153

154154
internal fun setupView(view: IView) {
@@ -168,6 +168,7 @@ class DesignerWorkspaceFragment : BaseFragment() {
168168
null -> view.view.foreground = bgDesignerView(requireContext())
169169
is UiViewLayeredForeground ->
170170
log.warn("Attempt to reset UiViewLayeredForeground on view", view.name, fg::class.java)
171+
171172
else -> view.view.foreground = layeredForeground(requireContext(), fg)
172173
}
173174

@@ -185,6 +186,7 @@ class DesignerWorkspaceFragment : BaseFragment() {
185186

186187
val existing = childFragmentManager.findFragmentByTag(ViewInfoSheet.TAG)
187188
if (existing == null) {
189+
val viewInfo = ViewInfoSheet()
188190
viewInfo.show(childFragmentManager, ViewInfoSheet.TAG)
189191
}
190192
}

0 commit comments

Comments
 (0)