@@ -39,10 +39,6 @@ internal class FragmentFlowRenderView(
39
39
private var fragmentState: FragmentFlowState ? = null
40
40
private val visibleFragments: LinkedList <Fragment > = LinkedList ()
41
41
42
- private var removedEarly = mutableListOf<FragmentId >()
43
- private var backStackEntries = mutableListOf<FragmentManager .BackStackEntry >()
44
- private var stateRestored: Boolean = false
45
-
46
42
private val featureProvider = object : FeatureProvider {
47
43
override fun getFeature (id : FragmentId ): FeatureEvent ? {
48
44
return fragmentState?.features?.get(id)
@@ -58,11 +54,6 @@ internal class FragmentFlowRenderView(
58
54
) {
59
55
super .onFragmentViewCreated(fm, f, v, savedInstanceState)
60
56
61
- if (! stateRestored) {
62
- recordBackstackChange()
63
- stateRestored = true
64
- }
65
-
66
57
visibleFragments.add(f)
67
58
68
59
fragmentState?.let {
@@ -98,9 +89,7 @@ internal class FragmentFlowRenderView(
98
89
visibleFragments.remove(f)
99
90
100
91
notifyLifecycleStateChanged(f, Lifecycle .State .DESTROYED )
101
- if (! removedEarly.contains(f.getFormulaFragmentId())) {
102
- onFragmentViewStateChanged(f.getFormulaFragmentId(), false )
103
- }
92
+ onFragmentViewStateChanged(f.getFormulaFragmentId(), false )
104
93
}
105
94
106
95
override fun onFragmentAttached (fm : FragmentManager , f : Fragment , context : Context ) {
@@ -125,19 +114,12 @@ internal class FragmentFlowRenderView(
125
114
// Only trigger detach, when fragment is actually being removed from the backstack
126
115
if (FragmentLifecycle .shouldTrack(f) && ! FragmentLifecycle .isKept(fm, f)) {
127
116
val event = FragmentLifecycle .createRemovedEvent(f)
128
- val wasRemovedEarly = removedEarly.remove(f.getFormulaFragmentId())
129
- if (! wasRemovedEarly) {
130
- onLifecycleEvent(event)
131
- }
117
+ onLifecycleEvent(event)
132
118
}
133
119
}
134
120
}
135
121
136
122
init {
137
- activity.supportFragmentManager.addOnBackStackChangedListener {
138
- recordBackstackChange()
139
- }
140
-
141
123
activity.supportFragmentManager.registerFragmentLifecycleCallbacks(callback, false )
142
124
}
143
125
@@ -176,36 +158,6 @@ internal class FragmentFlowRenderView(
176
158
}
177
159
}
178
160
179
- private fun recordBackstackChange () {
180
- val backStackEntryCount = backStackEntries.size
181
- val newBackStackEntryCount = activity.supportFragmentManager.backStackEntryCount
182
- if (backStackEntryCount > newBackStackEntryCount) {
183
- val removedEntries = backStackEntries.drop(newBackStackEntryCount)
184
- removedEntries.forEach { removed ->
185
- val poppedFragmentName = removed.name
186
- if (poppedFragmentName != null ) {
187
- visibleFragments.find { it.tag == poppedFragmentName }?.let { poppedFragment ->
188
- // In case backstack gets repopulated before onDestroyView/onFragmentDetached gets called,
189
- // we internally clear it so it doesn't potentially interfere with a fragment that could have the same contract
190
- removeFragment(poppedFragment)
191
- }
192
- }
193
- backStackEntries.remove(removed)
194
- }
195
- } else if (backStackEntryCount < newBackStackEntryCount) {
196
- for (i in backStackEntryCount until newBackStackEntryCount) {
197
- backStackEntries.add(activity.supportFragmentManager.getBackStackEntryAt(i))
198
- }
199
- }
200
- }
201
-
202
- private fun removeFragment (fragment : Fragment ) {
203
- onFragmentViewStateChanged(fragment.getFormulaFragmentId(), false )
204
- val event = FragmentLifecycle .createRemovedEvent(fragment)
205
- onLifecycleEvent(event)
206
- removedEarly.add(fragment.getFormulaFragmentId())
207
- }
208
-
209
161
/* *
210
162
* Creates a unique identifier the first time fragment is attached that
211
163
* is persisted across configuration changes.
0 commit comments