Skip to content

Commit 48a9e30

Browse files
committed
update Example to RN-0.52.0
1 parent 609de03 commit 48a9e30

35 files changed

+4353
-709
lines changed

Example/.flowconfig

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
; Ignore polyfills
1717
.*/Libraries/polyfills/.*
1818

19+
; Ignore metro
20+
.*/node_modules/metro/.*
21+
1922
[include]
2023

2124
[libs]
2225
node_modules/react-native/Libraries/react-native/react-native-interface.js
2326
node_modules/react-native/flow/
27+
node_modules/react-native/flow-github/
2428

2529
[options]
2630
emoji=true
@@ -31,18 +35,22 @@ munge_underscores=true
3135

3236
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
3337

38+
module.file_ext=.js
39+
module.file_ext=.jsx
40+
module.file_ext=.json
41+
module.file_ext=.native.js
42+
3443
suppress_type=$FlowIssue
3544
suppress_type=$FlowFixMe
3645
suppress_type=$FlowFixMeProps
3746
suppress_type=$FlowFixMeState
38-
suppress_type=$FixMe
3947

40-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
41-
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
48+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
49+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
4250
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
4351
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
4452

4553
unsafe.enable_getters_and_setters=true
4654

4755
[version]
48-
^0.56.0
56+
^0.61.0

Example/App.js

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
/**
1+
/**
22
* Sample React Native App
33
* https://github.com/facebook/react-native
44
* @flow
55
*/
66

77
import React, { Component } from "react";
8-
import { AppRegistry, StyleSheet, View, TextInput, ToastAndroid, DeviceEventEmitter } from "react-native";
8+
import { AppRegistry, StyleSheet, View, TextInput, ToastAndroid, DeviceEventEmitter, Platform, NativeEventEmitter } from "react-native";
99
import { Recognizer, Synthesizer, SpeechConstant } from "react-native-speech-iflytek";
1010
import Button from "react-native-button";
1111

1212
export default class App extends Component {
1313
constructor(props) {
1414
super(props);
1515

16+
if (Platform.OS === 'android') {
17+
Synthesizer.init("57c7c5b0");
18+
Recognizer.init("57c7c5b0");
19+
} else if (Platform.OS === 'ios') {
20+
Synthesizer.init("59a4161e");
21+
Recognizer.init("59a4161e");
22+
}
23+
1624
this.state = {
1725
text: "",
1826
recordBtnText: "Press to record"
@@ -22,20 +30,25 @@ export default class App extends Component {
2230
this.onRecordEnd = this.onRecordEnd.bind(this);
2331
this.onRecordCancel = this.onRecordCancel.bind(this);
2432
this.onRecognizerResult = this.onRecognizerResult.bind(this);
33+
this.onRecognizerError = this.onRecognizerError.bind(this);
2534
this.onRecognizerVolumeChanged = this.onRecognizerVolumeChanged.bind(this);
2635
this.onSyntheBtnPress = this.onSyntheBtnPress.bind(this);
2736
}
2837

2938
componentDidMount() {
30-
Synthesizer.init("57c7c5b0");
31-
Recognizer.init("57c7c5b0");
32-
DeviceEventEmitter.addListener("onRecognizerResult", this.onRecognizerResult);
33-
DeviceEventEmitter.addListener("onRecognizerVolumeChanged", this.onRecognizerVolumeChanged);
39+
this.recognizerEventEmitter = new NativeEventEmitter(Recognizer);
40+
this.recognizerEventEmitter.addListener('onRecognizerResult', this.onRecognizerResult)
41+
this.recognizerEventEmitter.addListener('onRecognizerError', this.onRecognizerError)
42+
this.recognizerEventEmitter.addListener('onRecognizerVolumeChanged', this.onRecognizerVolumeChanged)
43+
44+
this.synthesizerEventEmitter = new NativeEventEmitter(Synthesizer);
45+
this.synthesizerEventEmitter.addListener('onSynthesizerSpeakCompletedEvent', this.onSynthesizerSpeakCompletedEvent);
46+
this.synthesizerEventEmitter.addListener('onSynthesizerBufferCompletedEvent', this.onSynthesizerBufferCompletedEvent);
3447
}
3548

3649
componentWillUnmount() {
37-
DeviceEventEmitter.removeListener("onRecognizerResult", this.onRecognizerResult);
38-
DeviceEventEmitter.addListener("onRecognizerVolumeChanged", this.onRecognizerVolumeChanged);
50+
this.recognizerEventEmitter.removeAllListeners();
51+
this.synthesizerEventEmitter.removeAllListeners();
3952
}
4053

4154
render() {
@@ -61,20 +74,17 @@ export default class App extends Component {
6174
}
6275

6376
onRecordStart() {
64-
ToastAndroid.show("Begin to record", ToastAndroid.SHORT);
6577
this.setState({ recordBtnText: "Release to stop" });
66-
Synthesizer.setParameter(SpeechConstant.VOICE_NAME, "xiaoyu");
78+
6779
Recognizer.start();
6880
}
6981

7082
onRecordEnd() {
71-
ToastAndroid.show("End to record", ToastAndroid.SHORT);
7283
this.setState({ recordBtnText: "Press to record" });
7384
Recognizer.stop();
7485
}
7586

7687
onRecordCancel(evt) {
77-
ToastAndroid.show("cancel", ToastAndroid.SHORT);
7888
// setTimeout(() => {
7989
// Recognizer.cancel();
8090
// }, 500);
@@ -87,13 +97,26 @@ export default class App extends Component {
8797
this.setState({ text: e.result });
8898
}
8999

100+
onRecognizerError(result) {
101+
if (result.errorCode !== 0) {
102+
alert(JSON.stringify(result));
103+
}
104+
}
105+
90106
onRecognizerVolumeChanged() {
91107

92108
}
93109

94110
async onSyntheBtnPress() {
95-
let isSpeaking = await Synthesizer.isSpeaking();
96-
isSpeaking ? Synthesizer.stop() : Synthesizer.start(this.state.text);
111+
Synthesizer.start(this.state.text);
112+
}
113+
114+
onSynthesizerSpeakCompletedEvent(result) {
115+
alert('onSynthesizerSpeakCompletedEvent\n\n' + JSON.stringify(result));
116+
}
117+
118+
onSynthesizerBufferCompletedEvent(result) {
119+
// alert('onSynthesizerBufferCompletedEvent\n\n' + JSON.stringify(result));
97120
}
98121
}
99122

Example/android/app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ def enableSeparateBuildPerCPUArchitecture = false
9494
def enableProguardInReleaseBuilds = false
9595

9696
android {
97-
compileSdkVersion 25
98-
buildToolsVersion "25.0.3"
97+
compileSdkVersion 23
98+
buildToolsVersion "23.0.1"
9999

100100
defaultConfig {
101101
applicationId "com.example"
102102
minSdkVersion 16
103-
targetSdkVersion 25
103+
targetSdkVersion 22
104104
versionCode 1
105105
versionName "1.0"
106106
ndk {
@@ -139,7 +139,7 @@ android {
139139
dependencies {
140140
compile project(':react-native-speech-iflytek')
141141
compile fileTree(dir: "libs", include: ["*.jar"])
142-
compile "com.android.support:appcompat-v7:25.3.1"
142+
compile "com.android.support:appcompat-v7:23.0.1"
143143
compile "com.facebook.react:react-native:+" // From node_modules
144144
}
145145

Example/android/gradlew

100644100755
File mode changed.

Example/android/gradlew.bat

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,90 @@
1-
@if "%DEBUG%" == "" @echo off
2-
@rem ##########################################################################
3-
@rem
4-
@rem Gradle startup script for Windows
5-
@rem
6-
@rem ##########################################################################
7-
8-
@rem Set local scope for the variables with windows NT shell
9-
if "%OS%"=="Windows_NT" setlocal
10-
11-
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12-
set DEFAULT_JVM_OPTS=
13-
14-
set DIRNAME=%~dp0
15-
if "%DIRNAME%" == "" set DIRNAME=.
16-
set APP_BASE_NAME=%~n0
17-
set APP_HOME=%DIRNAME%
18-
19-
@rem Find java.exe
20-
if defined JAVA_HOME goto findJavaFromJavaHome
21-
22-
set JAVA_EXE=java.exe
23-
%JAVA_EXE% -version >NUL 2>&1
24-
if "%ERRORLEVEL%" == "0" goto init
25-
26-
echo.
27-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28-
echo.
29-
echo Please set the JAVA_HOME variable in your environment to match the
30-
echo location of your Java installation.
31-
32-
goto fail
33-
34-
:findJavaFromJavaHome
35-
set JAVA_HOME=%JAVA_HOME:"=%
36-
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37-
38-
if exist "%JAVA_EXE%" goto init
39-
40-
echo.
41-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42-
echo.
43-
echo Please set the JAVA_HOME variable in your environment to match the
44-
echo location of your Java installation.
45-
46-
goto fail
47-
48-
:init
49-
@rem Get command-line arguments, handling Windowz variants
50-
51-
if not "%OS%" == "Windows_NT" goto win9xME_args
52-
if "%@eval[2+2]" == "4" goto 4NT_args
53-
54-
:win9xME_args
55-
@rem Slurp the command line arguments.
56-
set CMD_LINE_ARGS=
57-
set _SKIP=2
58-
59-
:win9xME_args_slurp
60-
if "x%~1" == "x" goto execute
61-
62-
set CMD_LINE_ARGS=%*
63-
goto execute
64-
65-
:4NT_args
66-
@rem Get arguments from the 4NT Shell from JP Software
67-
set CMD_LINE_ARGS=%$
68-
69-
:execute
70-
@rem Setup the command line
71-
72-
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73-
74-
@rem Execute Gradle
75-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76-
77-
:end
78-
@rem End local scope for the variables with windows NT shell
79-
if "%ERRORLEVEL%"=="0" goto mainEnd
80-
81-
:fail
82-
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83-
rem the _cmd.exe /c_ return code!
84-
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85-
exit /b 1
86-
87-
:mainEnd
88-
if "%OS%"=="Windows_NT" endlocal
89-
90-
:omega
1+
@if "%DEBUG%" == "" @echo off
2+
@rem ##########################################################################
3+
@rem
4+
@rem Gradle startup script for Windows
5+
@rem
6+
@rem ##########################################################################
7+
8+
@rem Set local scope for the variables with windows NT shell
9+
if "%OS%"=="Windows_NT" setlocal
10+
11+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12+
set DEFAULT_JVM_OPTS=
13+
14+
set DIRNAME=%~dp0
15+
if "%DIRNAME%" == "" set DIRNAME=.
16+
set APP_BASE_NAME=%~n0
17+
set APP_HOME=%DIRNAME%
18+
19+
@rem Find java.exe
20+
if defined JAVA_HOME goto findJavaFromJavaHome
21+
22+
set JAVA_EXE=java.exe
23+
%JAVA_EXE% -version >NUL 2>&1
24+
if "%ERRORLEVEL%" == "0" goto init
25+
26+
echo.
27+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28+
echo.
29+
echo Please set the JAVA_HOME variable in your environment to match the
30+
echo location of your Java installation.
31+
32+
goto fail
33+
34+
:findJavaFromJavaHome
35+
set JAVA_HOME=%JAVA_HOME:"=%
36+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37+
38+
if exist "%JAVA_EXE%" goto init
39+
40+
echo.
41+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42+
echo.
43+
echo Please set the JAVA_HOME variable in your environment to match the
44+
echo location of your Java installation.
45+
46+
goto fail
47+
48+
:init
49+
@rem Get command-line arguments, handling Windowz variants
50+
51+
if not "%OS%" == "Windows_NT" goto win9xME_args
52+
if "%@eval[2+2]" == "4" goto 4NT_args
53+
54+
:win9xME_args
55+
@rem Slurp the command line arguments.
56+
set CMD_LINE_ARGS=
57+
set _SKIP=2
58+
59+
:win9xME_args_slurp
60+
if "x%~1" == "x" goto execute
61+
62+
set CMD_LINE_ARGS=%*
63+
goto execute
64+
65+
:4NT_args
66+
@rem Get arguments from the 4NT Shell from JP Software
67+
set CMD_LINE_ARGS=%$
68+
69+
:execute
70+
@rem Setup the command line
71+
72+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73+
74+
@rem Execute Gradle
75+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76+
77+
:end
78+
@rem End local scope for the variables with windows NT shell
79+
if "%ERRORLEVEL%"=="0" goto mainEnd
80+
81+
:fail
82+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83+
rem the _cmd.exe /c_ return code!
84+
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85+
exit /b 1
86+
87+
:mainEnd
88+
if "%OS%"=="Windows_NT" endlocal
89+
90+
:omega

0 commit comments

Comments
 (0)