@@ -15,14 +15,11 @@ class FastInflater private constructor(context: Context) {
1515
1616 private val appContext = context.applicationContext
1717 private val viewPool = ViewPool ()
18- private val registry = GeneratedLayoutRegistry ()
1918 // 单线程避免 LayoutInflater 并发访问 Resources 的线程安全问题(Android 8.x 及以下)
2019 private val asyncExecutor = Executors .newSingleThreadExecutor { r ->
2120 Thread (r, " FastInflater-async" ).apply { isDaemon = true }
2221 }
2322
24- fun registry (): GeneratedLayoutRegistry = registry
25-
2623 fun registerPolicy (@LayoutRes layoutId : Int , policy : ViewRecyclePolicy ) {
2724 viewPool.registerPolicy(layoutId, policy)
2825 }
@@ -61,13 +58,6 @@ class FastInflater private constructor(context: Context) {
6158
6259 PoolStats .recordMiss(layoutId)
6360
64- val creator = registry.resolve(context, layoutId)
65- if (creator != null ) {
66- return InflateTracker .track(layoutId) {
67- creator.create(context, parent, attachToRoot)
68- }
69- }
70-
7161 return InflateTracker .track(layoutId) {
7262 LayoutInflater .from(context).inflate(layoutId, parent, attachToRoot)
7363 }
@@ -95,15 +85,12 @@ class FastInflater private constructor(context: Context) {
9585
9686 PoolStats .recordMiss(layoutId)
9787
98- val creator = registry.resolve(context, layoutId)
99-
10088 // 已知必须主线程:直接在主线程 inflate,避免后台崩溃
10189 if (viewPool.isMainThreadOnly(layoutId)) {
10290 val handler = Handler (Looper .getMainLooper())
10391 val run = Runnable {
10492 val view = InflateTracker .track(layoutId) {
105- if (creator != null ) creator.create(context, parent, false )
106- else LayoutInflater .from(context).inflate(layoutId, parent, false )
93+ LayoutInflater .from(context).inflate(layoutId, parent, false )
10794 }
10895 callback(view)
10996 }
@@ -114,21 +101,16 @@ class FastInflater private constructor(context: Context) {
114101 asyncExecutor.execute {
115102 try {
116103 val view = InflateTracker .track(layoutId) {
117- if (creator != null ) {
118- creator.create(context, parent, false )
119- } else {
120- LayoutInflater .from(context).cloneInContext(context)
121- .inflate(layoutId, parent, false )
122- }
104+ LayoutInflater .from(context).cloneInContext(context)
105+ .inflate(layoutId, parent, false )
123106 }
124107 parent?.post { callback(view) } ? : callback(view)
125108 } catch (e: Throwable ) {
126109 // 后台 inflate 失败,标记并降级到主线程重试
127110 viewPool.markAsMainThreadOnly(layoutId)
128111 Handler (Looper .getMainLooper()).post {
129112 val view = InflateTracker .track(layoutId) {
130- if (creator != null ) creator.create(context, parent, false )
131- else LayoutInflater .from(context).inflate(layoutId, parent, false )
113+ LayoutInflater .from(context).inflate(layoutId, parent, false )
132114 }
133115 callback(view)
134116 }
0 commit comments