Skip to content

Commit

Permalink
Fixed a crash with dialogs opened from web views on Samsung devices r…
Browse files Browse the repository at this point in the history
…unning android 9
  • Loading branch information
B3nedikt committed Jan 2, 2024
1 parent 8196076 commit 1087aa0
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.webkit.WebView
import android.widget.CalendarView
import android.widget.DatePicker
import android.widget.NumberPicker
import android.widget.SearchView
import androidx.appcompat.widget.AlertDialogLayout
import androidx.appcompat.widget.ButtonBarLayout
Expand All @@ -18,10 +21,10 @@ import androidx.core.view.LayoutInflaterCompat
import dev.b3nedikt.viewpump.InflateRequest
import dev.b3nedikt.viewpump.InflateResult
import dev.b3nedikt.viewpump.ViewPump
import dev.b3nedikt.viewpump.internal.WebViewContextWrapper
import dev.b3nedikt.viewpump.WrapContext
import dev.b3nedikt.viewpump.internal.InterceptorChain
import dev.b3nedikt.viewpump.internal.LegacyLayoutInflater
import dev.b3nedikt.viewpump.internal.WebViewContextWrapper

/**
* A [AppCompatDelegate] to be used with [ViewPump]
Expand All @@ -43,6 +46,7 @@ class ViewPumpAppCompatDelegate @JvmOverloads constructor(
if (layoutInflater.factory == null) {
LayoutInflaterCompat.setFactory2(layoutInflater, this)
} else {
@SuppressLint("RestrictedApi")
if (layoutInflater.factory2 !is AppCompatDelegateImpl) {
Log.i(
TAG, "The Activity's LayoutInflater already has a Factory installed"
Expand Down Expand Up @@ -184,6 +188,17 @@ class ViewPumpAppCompatDelegate @JvmOverloads constructor(
"com.android.internal.widget.ButtonBarLayout" ->
ButtonBarLayout(createWrappedContext(), attrs)

// The following three widgets only exist on Samsung devices with android 9,
// we replace them with their counterparts from android.widgets
"com.android.internal.widget.CalendarView" ->
CalendarView(createWrappedContext(), attrs)

"com.android.internal.widget.DatePicker" ->
DatePicker(createWrappedContext(), attrs)

"com.android.internal.widget.NumberPicker" ->
NumberPicker(createWrappedContext(), attrs)

else -> view
}
}
Expand Down

0 comments on commit 1087aa0

Please sign in to comment.