File tree Expand file tree Collapse file tree 6 files changed +45
-1
lines changed Expand file tree Collapse file tree 6 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
10
10
} from "react-native" ;
11
11
12
12
const getSuggestions = require ( "./trie-service.js" ) ;
13
+ const keysWithPrefix = require ( "./trie-from-idiom.js" ) . keysWithPrefix ;
13
14
14
15
type Props = { } ;
15
16
export default class App extends Component < Props > {
@@ -30,6 +31,22 @@ export default class App extends Component<Props> {
30
31
}
31
32
} ;
32
33
34
+ onChangeText2 = text => {
35
+ text = text . trim ( ) . toLowerCase ( ) ;
36
+ if ( text ) {
37
+ const suggestions = keysWithPrefix ( text ) . map ( item => {
38
+ return { word : item } ;
39
+ } ) ;
40
+ this . setState ( {
41
+ suggestions : suggestions
42
+ } ) ;
43
+ } else {
44
+ this . setState ( {
45
+ suggestions : [ ]
46
+ } ) ;
47
+ }
48
+ } ;
49
+
33
50
keyExtractor = item => item . word ;
34
51
35
52
render ( ) {
@@ -45,14 +62,22 @@ export default class App extends Component<Props> {
45
62
autoCapitalize = "none"
46
63
placeholder = "Input the word..."
47
64
/>
65
+ < TextInput
66
+ style = { styles . input }
67
+ onChangeText = { this . onChangeText2 }
68
+ autoFocus = { true }
69
+ autoCorrect = { false }
70
+ autoCapitalize = "none"
71
+ placeholder = "成语接龙..."
72
+ />
48
73
< FlatList
49
74
style = { styles . list }
50
75
data = { suggestions }
51
76
keyExtractor = { this . keyExtractor }
52
77
renderItem = { ( { item } ) => (
53
78
< View style = { styles . item } >
54
79
< Text >
55
- { item . word } : { item . ipa ? "[ " + item . ipa + " ]" : "" }
80
+ { item . word } { item . ipa ? " [ " + item . ipa + " ]" : " " }
56
81
{ item . translation && " " + item . translation . join ( " " ) }
57
82
</ Text >
58
83
</ View >
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ Built by react-native.
7
7
1 . instant translate english to chinese when typing
8
8
2 . instant spell-check when typing
9
9
3 . show IPA of inputed word
10
+ 4 . 成语接龙
10
11
11
12
### android dev
12
13
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 13
13
},
14
14
"dependencies" : {
15
15
"dawg-lookup" : " ^2.2.1" ,
16
+ "node-ternary-search-trie" : " ^5.4.3" ,
16
17
"react" : " 16.8.3" ,
17
18
"react-native" : " 0.59.8" ,
18
19
"typo-js" : " ^1.0.3"
Original file line number Diff line number Diff line change
1
+ const Trie = require ( "node-ternary-search-trie" ) ;
2
+ const trie = new Trie ( ) ;
3
+ const data = require ( "./idiom.json" ) ;
4
+ data . forEach ( element => {
5
+ trie . set ( element , 0 ) ;
6
+ } ) ;
7
+ // console.time("time");
8
+ // console.log("keysWithPrefix pref", trie.keysWithPrefix("渊"));
9
+ // console.timeEnd("time");
10
+
11
+ module . exports = trie ;
Original file line number Diff line number Diff line change @@ -4269,6 +4269,11 @@ node-pre-gyp@^0.12.0:
4269
4269
semver "^5.3.0"
4270
4270
tar "^4"
4271
4271
4272
+ node-ternary-search-trie@^5.4.3 :
4273
+ version "5.4.3"
4274
+ resolved "https://registry.yarnpkg.com/node-ternary-search-trie/-/node-ternary-search-trie-5.4.3.tgz#452dd2549a7d70ed2802016e7a6987ca4f1a3011"
4275
+ integrity sha512-DbCM1O2qNShPmWHqno+z39GNgk6LNfFImjkjn6jZM6lgyAwWrFNiOzIQb2wGJ2NprjRlJWS6GAufkuvr+s+pBA==
4276
+
4272
4277
nopt@^4.0.1 :
4273
4278
version "4.0.1"
4274
4279
resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.1.tgz#d0d4685afd5415193c8c7505602d0d17cd64474d"
You can’t perform that action at this time.
0 commit comments