Skip to content

Commit

Permalink
feat!: sdk 52 support (#53)
Browse files Browse the repository at this point in the history
* feat!: sdk 52 support

* fix: web support

* fix: android build

* chore: update ios build

* remove unused import

* fix: remove bindings from stop & abort
  • Loading branch information
jamsch authored Nov 17, 2024
1 parent 30b22ab commit 8a3f597
Show file tree
Hide file tree
Showing 73 changed files with 7,817 additions and 8,896 deletions.
9 changes: 9 additions & 0 deletions .changeset/brave-bananas-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"expo-speech-recognition": major
---

Support for SDK 52.

### Breaking Changes:

- Removed `ExpoSpeechRecognitionModuleEmitter`. Use `ExpoSpeechRecognitionModule.addListener` instead.
57 changes: 23 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ expo-speech-recognition implements the iOS [`SFSpeechRecognizer`](https://develo
- [requestPermissionsAsync()](#requestpermissionsasync-promisepermissionresponse)
- [getPermissionsAsync()](#getpermissionsasync-promisepermissionresponse)
- [getStateAsync()](#getstateasync-promisespeechrecognitionstate)
- [addSpeechRecognitionListener()](#addspeechrecognitionlistener)
- [getSupportedLocales()](#getsupportedlocales)
- [getSpeechRecognitionServices()](#getspeechrecognitionservices-string-android-only)
- [getDefaultRecognitionService()](#getdefaultrecognitionservice--packagename-string--android-only)
Expand Down Expand Up @@ -168,7 +167,10 @@ function App() {
{!recognizing ? (
<Button title="Start" onPress={handleStart} />
) : (
<Button title="Stop" onPress={ExpoSpeechRecognitionModule.stop} />
<Button
title="Stop"
onPress={() => ExpoSpeechRecognitionModule.stop()}
/>
)}

<ScrollView>
Expand Down Expand Up @@ -208,32 +210,35 @@ ExpoSpeechRecognitionModule.requestPermissionsAsync().then((result) => {
You can also use the `ExpoSpeechRecognitionModule` to use the native APIs directly. The listener events are similar to the Web Speech API.

```ts
import {
ExpoSpeechRecognitionModule,
addSpeechRecognitionListener,
} from "expo-speech-recognition";
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";

// Register event listeners
const startListener = addSpeechRecognitionListener("start", () => {
const startListener = ExpoSpeechRecognitionModule.addListener("start", () => {
console.log("Speech recognition started");
});

// and remove the listener when you're done:
startListener.remove();

const endListener = addSpeechRecognitionListener("end", () => {
const endListener = ExpoSpeechRecognitionModule.addListener("end", () => {
console.log("Speech recognition ended");
});

const resultListener = addSpeechRecognitionListener("result", (event) => {
// Note: this is not the same as the `result` event listener on the web speech API
// event.results is an array of results (e.g. `[{ transcript: "hello", confidence: 0.5, segments: [] }]`)
console.log("results:", event.results, "final:", event.isFinal);
});
const resultListener = ExpoSpeechRecognitionModule.addListener(
"result",
(event) => {
// Note: this is not the same as the `result` event listener on the web speech API
// event.results is an array of results (e.g. `[{ transcript: "hello", confidence: 0.5, segments: [] }]`)
console.log("results:", event.results, "final:", event.isFinal);
},
);

const errorListener = addSpeechRecognitionListener("error", (event) => {
console.log("error code:", event.error, "error message:", event.message);
});
const errorListener = ExpoSpeechRecognitionModule.addListener(
"error",
(event) => {
console.log("error code:", event.error, "error message:", event.message);
},
);

// Start speech recognition
ExpoSpeechRecognitionModule.start({
Expand Down Expand Up @@ -347,11 +352,11 @@ To handle errors, you can listen to the `error` event:
```ts
import {
type ExpoSpeechRecognitionErrorCode,
addSpeechRecognitionListener,
ExpoSpeechRecognitionModule,
useSpeechRecognitionEvent,
} from "expo-speech-recognition";

addSpeechRecognitionListener("error", (event) => {
ExpoSpeechRecognitionModule.addListener("error", (event) => {
console.log("error code:", event.error, "error message:", event.message);
});

Expand Down Expand Up @@ -873,22 +878,6 @@ ExpoSpeechRecognitionModule.getStateAsync().then((state) => {
});
```

### `addSpeechRecognitionListener()`

Refer to [Speech Recognition Events](#speech-recognition-events) for the list of supported events.

```ts
import { addSpeechRecognitionListener } from "expo-speech-recognition";

const listener = addSpeechRecognitionListener("result", (event) => {
console.log("transcript:", event.results[0]?.transcript);
console.log("confidence:", event.results[0]?.confidence);
});

// Remove the listener when you're done
listener.remove();
```

### `getSupportedLocales()`

> [!NOTE]
Expand Down
4 changes: 2 additions & 2 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ export default function App() {
<BigButton
title="Stop"
disabled={status !== "recognizing"}
onPress={ExpoSpeechRecognitionModule.stop}
onPress={() => ExpoSpeechRecognitionModule.stop()}
/>
<BigButton
title="Abort"
disabled={status !== "recognizing"}
onPress={ExpoSpeechRecognitionModule.abort}
onPress={() => ExpoSpeechRecognitionModule.abort()}
/>
</View>
)}
Expand Down
47 changes: 11 additions & 36 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,6 @@ apply plugin: "com.facebook.react"

def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath()

static def versionToNumber(major, minor, patch) {
return patch * 100 + minor * 10000 + major * 1000000
}

def getRNVersion() {
def version = providers.exec {
workingDir(projectDir)
commandLine("node", "-e", "console.log(require('react-native/package.json').version);")
}.standardOutput.asText.get().trim()

def coreVersion = version.split("-")[0]
def (major, minor, patch) = coreVersion.tokenize('.').collect { it.toInteger() }

return versionToNumber(
major,
minor,
patch
)
}
def rnVersion = getRNVersion()

/**
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
Expand All @@ -41,12 +20,12 @@ react {
bundleCommand = "export:embed"

/* Folders */
// The root of your project, i.e. where "package.json" lives. Default is '..'
// root = file("../")
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
// reactNativeDir = file("../node_modules/react-native")
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
// codegenDir = file("../node_modules/@react-native/codegen")
// The root of your project, i.e. where "package.json" lives. Default is '../..'
// root = file("../../")
// The folder where the react-native NPM package is. Default is ../../node_modules/react-native
// reactNativeDir = file("../../node_modules/react-native")
// The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen
// codegenDir = file("../../node_modules/@react-native/codegen")

/* Variants */
// The list of variants to that are debuggable. For those we're going to
Expand Down Expand Up @@ -79,10 +58,8 @@ react {
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
// hermesFlags = ["-O", "-output-source-map"]

if (rnVersion >= versionToNumber(0, 75, 0)) {
/* Autolinking */
autolinkLibrariesWithApp()
}
/* Autolinking */
autolinkLibrariesWithApp()
}

/**
Expand Down Expand Up @@ -144,6 +121,9 @@ android {
useLegacyPackaging (findProperty('expo.useLegacyPackaging')?.toBoolean() ?: false)
}
}
androidResources {
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~'
}
}

// Apply static values from `gradle.properties` to the `android.packagingOptions`
Expand Down Expand Up @@ -194,8 +174,3 @@ dependencies {
implementation jscFlavor
}
}

if (rnVersion < versionToNumber(0, 75, 0)) {
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
applyNativeModulesAppBuildGradle(project)
}
3 changes: 1 addition & 2 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<action android:name="android.speech.RecognitionService"/>
</intent>
</queries>
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="true" android:theme="@style/AppTheme">
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="true" android:theme="@style/AppTheme" android:supportsRtl="true">
<meta-data android:name="expo.modules.updates.ENABLED" android:value="false"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
Expand All @@ -41,6 +41,5 @@
<data android:scheme="expo.modules.speechrecognition.example"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package expo.modules.speechrecognition.example
import expo.modules.splashscreen.SplashScreenManager

import android.os.Build
import android.os.Bundle
Expand All @@ -15,7 +16,10 @@ class MainActivity : ReactActivity() {
// Set the theme to AppTheme BEFORE onCreate to support
// coloring the background, status bar, and navigation bar.
// This is required for expo-splash-screen.
setTheme(R.style.AppTheme);
// setTheme(R.style.AppTheme);
// @generated begin expo-splashscreen - expo prebuild (DO NOT MODIFY) sync-f3ff59a738c56c9a6119210cb55f0b613eb8b6af
SplashScreenManager.registerOnActivity(this)
// @generated end expo-splashscreen
super.onCreate(null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.facebook.react.ReactPackage
import com.facebook.react.ReactHost
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.soloader.OpenSourceMergedSoMapping
import com.facebook.soloader.SoLoader

import expo.modules.ApplicationLifecycleDispatcher
Expand All @@ -21,9 +22,10 @@ class MainApplication : Application(), ReactApplication {
this,
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> {
val packages = PackageList(this).packages
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return PackageList(this).packages
return packages
}

override fun getJSMainModuleName(): String = ".expo/.virtual-metro-entry"
Expand All @@ -40,7 +42,7 @@ class MainApplication : Application(), ReactApplication {

override fun onCreate() {
super.onCreate()
SoLoader.init(this, false)
SoLoader.init(this, OpenSourceMergedSoMapping)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/splashscreen_background"/>
<item>
<bitmap android:gravity="center" android:src="@drawable/splashscreen_logo"/>
</item>
</layer-list>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions example/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<item name="android:textColorHint">#c8c8c8</item>
<item name="android:textColor">@android:color/black</item>
</style>
<style name="Theme.App.SplashScreen" parent="AppTheme">
<item name="android:windowBackground">@drawable/splashscreen</item>
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/splashscreen_background</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/splashscreen_logo</item>
<item name="postSplashScreenTheme">@style/AppTheme</item>
</style>
</resources>
8 changes: 4 additions & 4 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

buildscript {
ext {
buildToolsVersion = findProperty('android.buildToolsVersion') ?: '34.0.0'
minSdkVersion = Integer.parseInt(findProperty('android.minSdkVersion') ?: '23')
compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '34')
buildToolsVersion = findProperty('android.buildToolsVersion') ?: '35.0.0'
minSdkVersion = Integer.parseInt(findProperty('android.minSdkVersion') ?: '24')
compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '35')
targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '34')
kotlinVersion = findProperty('android.kotlinVersion') ?: '1.9.23'
kotlinVersion = findProperty('android.kotlinVersion') ?: '1.9.24'

ndkVersion = "26.1.10909125"
}
Expand Down
3 changes: 0 additions & 3 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true

# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

# Enable AAPT2 PNG crunching
android.enablePngCrunchInReleaseBuilds=true

Expand Down
Binary file modified example/android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions example/android/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions example/android/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
19 changes: 0 additions & 19 deletions example/android/react-settings-plugin/build.gradle.kts

This file was deleted.

This file was deleted.

Loading

0 comments on commit 8a3f597

Please sign in to comment.