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

Commit 1133347

Browse files
committed
fix(uidesigner): do not keep a reference to LayoutInflater instance
1 parent ece8257 commit 1133347

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class DesignerWorkspaceFragment : BaseFragment() {
5858

5959
private var _viewInfo: ViewInfoSheet? = null
6060
private val touchSlop by lazy { get(requireContext()).scaledTouchSlop }
61-
private val inflater by lazy { UiLayoutInflater() }
6261

6362
private val viewInfo: ViewInfoSheet
6463
get() = this._viewInfo ?: ViewInfoSheet().also { _viewInfo = it }
@@ -86,7 +85,6 @@ class DesignerWorkspaceFragment : BaseFragment() {
8685

8786
private val hierarchyHandler by lazy { WorkspaceViewHierarchyHandler() }
8887
private val attrHandler by lazy { WorkspaceViewAttrHandler() }
89-
private val inflationHandler by lazy { WorkspaceLayoutInflationHandler() }
9088

9189
companion object {
9290
const val DRAGGING_WIDGET = "DRAGGING_WIDGET"
@@ -105,7 +103,6 @@ class DesignerWorkspaceFragment : BaseFragment() {
105103
this.binding = FragmentDesignerWorkspaceBinding.inflate(inflater, container, false)
106104
hierarchyHandler.init(this)
107105
attrHandler.init(this)
108-
inflationHandler.init(this)
109106
return this.binding!!.root
110107
}
111108

@@ -115,7 +112,12 @@ class DesignerWorkspaceFragment : BaseFragment() {
115112
viewModel._workspaceScreen.observe(viewLifecycleOwner) { binding?.flipper?.displayedChild = it }
116113
viewModel._errText.observe(viewLifecycleOwner) { binding?.errText?.text = it }
117114

118-
inflater.inflationEventListener = this.inflationHandler
115+
val inflationHandler = WorkspaceLayoutInflationHandler()
116+
inflationHandler.init(this)
117+
118+
val inflater = UiLayoutInflater()
119+
inflater.inflationEventListener = inflationHandler
120+
119121
val inflated =
120122
try {
121123
inflater.inflate(viewModel.file, workspaceView).also {
@@ -126,6 +128,9 @@ class DesignerWorkspaceFragment : BaseFragment() {
126128
viewModel.errText = "${e.message}${e.cause?.message?.let { "\n$it" } ?: ""}"
127129
viewModel.layoutHasError = true
128130
emptyList()
131+
} finally {
132+
inflationHandler.release()
133+
inflater.close()
129134
}
130135

131136
if (inflated.isEmpty() && !viewModel.layoutHasError) {
@@ -140,11 +145,10 @@ class DesignerWorkspaceFragment : BaseFragment() {
140145
override fun onDestroyView() {
141146
super.onDestroyView()
142147
this.binding = null
148+
this._viewInfo?.dismiss()
143149
this._viewInfo = null
144150
this.hierarchyHandler.release()
145151
this.attrHandler.release()
146-
this.inflationHandler.release()
147-
this.inflater.close()
148152
}
149153

150154
internal fun setupView(view: IView) {

uidesigner/src/main/java/com/itsaky/androidide/uidesigner/utils/UiLayoutInflater.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ class UiLayoutInflater : LayoutInflaterImpl() {
3030

3131
init {
3232
this.componentFactory = UiInflaterComponentFactory()
33-
Lookup.getDefault().update(com.itsaky.androidide.inflater.ILayoutInflater.LOOKUP_KEY, this)
33+
Lookup.getDefault().update(ILayoutInflater.LOOKUP_KEY, this)
3434
}
3535
}

0 commit comments

Comments
 (0)