Skip to content

Commit

Permalink
fix(onfocus-alpha): fix on autmatic add alpha on no focus view
Browse files Browse the repository at this point in the history
  • Loading branch information
andrefelipeschulle committed Oct 31, 2023
1 parent 9913a0c commit 97e8137
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 9 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ function Item({index}: ItemProps) {
}}
onCodeScanned={value => {
setValueText(value);
console.log(value === 'A000A');
}}
onSingleCodeScanned={value => {
console.log(value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.brainylab.reactnativeexternalscanner

import android.content.Context
import android.util.Log
import android.view.KeyEvent
import android.view.View
import android.view.View.OnFocusChangeListener
Expand All @@ -24,8 +23,7 @@ class ReactNativeExternalScannerView(context: Context) : ViewGroup(context) {
setOnKeyListener(null)

setOnFocusChangeListener(
OnFocusChangeListener { _, hasFocus ->
Log.i("APP SPE", "not focus")
OnFocusChangeListener { view, hasFocus ->
if (!hasFocus) {
val reactContext = context as ReactContext

Expand Down Expand Up @@ -95,10 +93,9 @@ class ReactNativeExternalScannerView(context: Context) : ViewGroup(context) {
}

fun setViewAddFocus() {
Log.i("APP SPE", "view focus")
isFocusableInTouchMode = true
requestFocus()
// Adicionar o OnKeyListener quando o setViewFocus for chamado

if (keyListener == null) {
keyListener =
OnKeyListener { _, keyCode, event ->
Expand Down Expand Up @@ -141,11 +138,9 @@ class ReactNativeExternalScannerView(context: Context) : ViewGroup(context) {
}

fun setViewClearFocus() {
Log.i("APP SPE", "view clear")
isFocusableInTouchMode = false
clearFocus()

// Remover o OnKeyListener quando o setClearFocus for chamado
if (keyListener != null) {
setOnKeyListener(null)
keyListener = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class ReactNativeExternalScannerViewManager(private val mCallerContext: ReactApp
@ReactProp(name = "active")
override fun setActive(view: ReactNativeExternalScannerView, active: Boolean) {
if(active) {
view.isEnabled = true
view.setViewAddFocus()
} else {
view.isEnabled = false
view.setViewClearFocus()
}
}
Expand Down
1 change: 0 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function Item({index}: ItemProps) {
}}
onCodeScanned={value => {
setValueText(value);
console.log(value === 'A000A');
}}
onSingleCodeScanned={value => {
console.log(value);
Expand Down

0 comments on commit 97e8137

Please sign in to comment.