-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from brainylab/features
feat(initalizing-project): iniciando projeto
- Loading branch information
Showing
26 changed files
with
16,798 additions
and
90 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
lib/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: ['@brainylab/eslint-config-react-native'], | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
arrowParens: 'avoid', | ||
bracketSameLine: true, | ||
bracketSpacing: false, | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ import groovy.json.JsonSlurper | |
def registrationCompat = { | ||
def reactNativeManifest = file("$projectDir/../node_modules/react-native/package.json").exists() | ||
? file("$projectDir/../node_modules/react-native/package.json") // developer mode, to run example app | ||
: file("$projectDir/../../react-native/package.json") | ||
: file("$projectDir/../../../react-native/package.json") | ||
def reactNativeVersion = new JsonSlurper().parseText(reactNativeManifest.text).version as String | ||
// Fabric was introduced at [email protected], full CMake support were introduced at [email protected] | ||
// Use Android.mk for compatibility with [email protected]/0.69 | ||
|
44 changes: 44 additions & 0 deletions
44
android/src/main/java/com/brainylab/reactnativeexternalscanner/ExternalScannerUtil.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.brainylab.reactnativeexternalscanner | ||
|
||
import android.content.Context | ||
import android.content.res.Configuration | ||
import android.view.InputDevice | ||
import android.view.KeyCharacterMap | ||
import android.view.inputmethod.InputMethodManager | ||
import com.facebook.react.bridge.Promise | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
|
||
object ExternalScannerUtil { | ||
fun isExternalScanner(inputDevice: InputDevice, resourcesConfiguration: Configuration): Boolean { | ||
val sources = inputDevice.sources | ||
if ((sources and InputDevice.SOURCE_KEYBOARD) != InputDevice.SOURCE_KEYBOARD) { | ||
return false // Not a keyboard device | ||
} | ||
|
||
// Check if the device has a key character map | ||
val keyCharacterMap = inputDevice.keyCharacterMap | ||
if (keyCharacterMap == null || keyCharacterMap.keyboardType == KeyCharacterMap.VIRTUAL_KEYBOARD) { | ||
return false // Virtual (on-screen) keyboard | ||
} | ||
|
||
// Check if the device has a physical keyboard (i.e., not a virtual keyboard) | ||
val hasPhysicalKeyboard = (resourcesConfiguration.keyboard != Configuration.KEYBOARD_NOKEYS) | ||
|
||
// If it has a physical keyboard, and it's not virtual (emulator or virtual device) | ||
return hasPhysicalKeyboard && !inputDevice.isVirtual | ||
} | ||
|
||
fun hasExternalScanner(reactContext: ReactApplicationContext): Boolean { | ||
val inputManager = reactContext.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | ||
val inputDevices = InputDevice.getDeviceIds() | ||
val resourcesConfiguration = reactContext.resources.configuration | ||
|
||
for (deviceId in inputDevices) { | ||
val device = InputDevice.getDevice(deviceId) | ||
if (device != null && isExternalScanner(device, resourcesConfiguration)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...main/java/com/brainylab/reactnativeexternalscanner/ExternalScannerViewSingleValueEvent.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.brainylab.reactnativeexternalscanner | ||
|
||
import com.facebook.react.bridge.Arguments | ||
import com.facebook.react.bridge.WritableMap | ||
import com.facebook.react.uimanager.events.Event | ||
import com.facebook.react.uimanager.events.RCTModernEventEmitter | ||
|
||
|
||
class ExternalScannerViewSingleValueEvent(viewId: Int, private val codeValue: String): Event<ExternalScannerViewSingleValueEvent>(viewId) { | ||
override fun getEventName(): String { | ||
return "topOnSingleValueScanned" | ||
} | ||
|
||
override fun dispatchModern(rctEventEmitter: RCTModernEventEmitter?) { | ||
super.dispatchModern(rctEventEmitter) | ||
rctEventEmitter?.receiveEvent( | ||
-1, | ||
viewTag, eventName, | ||
Arguments.createMap() | ||
) | ||
} | ||
|
||
override fun getEventData(): WritableMap { | ||
val event: WritableMap = Arguments.createMap() | ||
event.putString("value", codeValue) | ||
return event | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...d/src/main/java/com/brainylab/reactnativeexternalscanner/ExternalScannerViewValueEvent.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.brainylab.reactnativeexternalscanner | ||
|
||
import com.facebook.react.bridge.Arguments | ||
import com.facebook.react.bridge.WritableMap | ||
import com.facebook.react.uimanager.events.Event | ||
import com.facebook.react.uimanager.events.RCTModernEventEmitter | ||
|
||
|
||
class ExternalScannerViewValueEvent(viewId: Int, private val codeValue: String): Event<ExternalScannerViewValueEvent>(viewId) { | ||
override fun getEventName(): String { | ||
return "topOnValueScanned" | ||
} | ||
|
||
override fun dispatchModern(rctEventEmitter: RCTModernEventEmitter?) { | ||
super.dispatchModern(rctEventEmitter) | ||
rctEventEmitter?.receiveEvent( | ||
-1, | ||
viewTag, eventName, | ||
Arguments.createMap() | ||
) | ||
} | ||
|
||
override fun getEventData(): WritableMap { | ||
val event: WritableMap = Arguments.createMap() | ||
event.putString("value", codeValue) | ||
return event | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...rc/main/java/com/brainylab/reactnativeexternalscanner/ReactNativeExternalScannerModule.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.brainylab.reactnativeexternalscanner | ||
|
||
import android.content.Context | ||
import android.content.res.Configuration | ||
import android.view.InputDevice | ||
import android.view.KeyCharacterMap | ||
import android.view.KeyEvent | ||
import android.view.inputmethod.InputMethodManager | ||
import com.facebook.react.bridge.* | ||
import com.facebook.react.modules.core.DeviceEventManagerModule | ||
|
||
class ReactNativeExternalScannerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { | ||
override fun getName(): String { | ||
return "ReactNativeExternalScannerModule" | ||
} | ||
|
||
@ReactMethod | ||
fun hasExternalKeyboard(promise: Promise) { | ||
val isExternal = ExternalScannerUtil.hasExternalScanner(reactApplicationContext) | ||
|
||
if(isExternal) { | ||
promise.resolve(true) | ||
} else { | ||
promise.resolve(false) | ||
} | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const path = require('path'); | ||
|
||
const pak = require('../package.json'); | ||
|
||
module.exports = { | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { AppRegistry } from 'react-native'; | ||
import {AppRegistry} from 'react-native'; | ||
|
||
import {name as appName} from './app.json'; | ||
import App from './src/App'; | ||
import { name as appName } from './app.json'; | ||
|
||
AppRegistry.registerComponent(appName, () => App); |
Oops, something went wrong.