-
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.
feat: allow launching from text selection toolbar
- Loading branch information
Showing
37 changed files
with
515 additions
and
1,824 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 @@ | ||
/src/components/QueryScreen/darkreader.js |
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
This file was deleted.
Oops, something went wrong.
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
75 changes: 0 additions & 75 deletions
75
android/app/src/debug/java/com/silverdict/ReactNativeFlipper.java
This file was deleted.
Oops, something went wrong.
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
66 changes: 66 additions & 0 deletions
66
android/app/src/main/java/com/gmail/blandilyte/silverdict/MainActivity.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,66 @@ | ||
package com.gmail.blandilyte.silverdict | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.util.Log | ||
import com.facebook.react.ReactActivity | ||
import com.facebook.react.ReactActivityDelegate | ||
import com.facebook.react.bridge.Arguments | ||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled | ||
import com.facebook.react.defaults.DefaultReactActivityDelegate | ||
import com.facebook.react.modules.core.DeviceEventManagerModule | ||
|
||
class MainActivity : ReactActivity() { | ||
|
||
override fun getMainComponentName(): String = "SilverDict" | ||
|
||
override fun createReactActivityDelegate(): ReactActivityDelegate = | ||
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled) | ||
|
||
// Define PROCESS_TEXT intent action and send it to the React Native app | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
handleIntent(intent) | ||
} | ||
|
||
override fun onNewIntent(intent: Intent?) { | ||
super.onNewIntent(intent) | ||
handleIntent(intent) | ||
} | ||
|
||
private fun handleIntent(intent: Intent?) { | ||
if (intent?.action == Intent.ACTION_PROCESS_TEXT) { | ||
val selectedText = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT) | ||
Log.d("MainActivity", "Selected text: $selectedText") | ||
|
||
if (reactInstanceManager.currentReactContext != null) { | ||
sendTextToReactNative(selectedText.toString()) | ||
} else { | ||
Log.d("MainActivity", "ReactContext is null, polling") | ||
pollReactContextAndSendText(selectedText.toString()) | ||
} | ||
} | ||
} | ||
|
||
private fun pollReactContextAndSendText(selectedText: String) { | ||
Thread { | ||
while (reactInstanceManager.currentReactContext == null) { | ||
Thread.sleep(50) | ||
} | ||
// The processing code is nested very deep inside the React Native part, | ||
// So sleep for a bit more. | ||
Thread.sleep(150) | ||
sendTextToReactNative(selectedText) | ||
Log.d("MainActivity", "ReactContext is no longer null, text sent") | ||
}.start() | ||
} | ||
|
||
private fun sendTextToReactNative(selectedText: String) { | ||
val params = Arguments.createMap() | ||
params.putString("selectedText", selectedText) | ||
|
||
reactInstanceManager.currentReactContext | ||
?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) | ||
?.emit("onTextSelected", params) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
android/app/src/main/java/com/gmail/blandilyte/silverdict/MainApplication.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,41 @@ | ||
package com.gmail.blandilyte.silverdict | ||
|
||
import android.app.Application | ||
import com.facebook.react.PackageList | ||
import com.facebook.react.ReactApplication | ||
import com.facebook.react.ReactHost | ||
import com.facebook.react.ReactNativeHost | ||
import com.facebook.react.ReactPackage | ||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load | ||
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost | ||
import com.facebook.react.defaults.DefaultReactNativeHost | ||
import com.facebook.soloader.SoLoader | ||
|
||
class MainApplication : Application(), ReactApplication { | ||
|
||
override val reactNativeHost: ReactNativeHost = object : DefaultReactNativeHost(this) { | ||
override fun getPackages(): List<ReactPackage> = PackageList(this).packages.apply { | ||
// Packages that cannot be autolinked yet can be added manually here, for example: | ||
// add(MyReactNativePackage()) | ||
} | ||
|
||
override fun getJSMainModuleName(): String = "index" | ||
|
||
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG | ||
|
||
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED | ||
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED | ||
} | ||
|
||
override val reactHost: ReactHost | ||
get() = getDefaultReactHost(applicationContext, reactNativeHost) | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
SoLoader.init(this, false) | ||
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { | ||
// If you opted-in for the New Architecture, we load the native entry point for this app. | ||
load() | ||
} | ||
} | ||
} |
Oops, something went wrong.