Last active
March 4, 2022 12:56
-
-
Save olegsvs/b86b43d317a751f77fba683e892ad787 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.graphics.Rect | |
import android.os.Build | |
import android.text.InputType | |
import android.util.AttributeSet | |
import com.rengwuxian.materialedittext.MaterialEditText | |
import java.util.* | |
/* | |
fixes for xiaomi devices editText with inputType email | |
StackTrace: http://prntscr.com/upz1au and http://prntscr.com/upz1s0 | |
https://c.mi.com/thread-3171961-1-0.html | |
https://github.com/facebook/react-native/issues/27204 | |
https://stackoverflow.com/questions/63558592/nullpointerexception-in-textinputlayout-on-xiaomi-with-android-10 | |
*/ | |
class FixedMaterialEditText : MaterialEditText { | |
val brandsNeedingWorkaround = arrayOf("redmi", "xiaomi", "poco", "pocophone") | |
constructor(context: Context) : super(context) | |
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) | |
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super( | |
context, | |
attrs, | |
defStyleAttr | |
) | |
override fun onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?) { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
if (this.inputType.equals(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS) || | |
this.inputType.equals(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS) | |
) { | |
if (brandsNeedingWorkaround.contains(Build.BRAND.toLowerCase(Locale.ROOT))) { | |
this.isCursorVisible = false | |
} | |
} | |
} | |
super.onFocusChanged(focused, direction, previouslyFocusedRect) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment