@@ -2,15 +2,15 @@ import React, {Component, PropTypes} from 'react';
2
2
import WebViewBridge from 'react-native-webview-bridge-updated' ;
3
3
import { InjectedMessageHandler } from './WebviewMessageHandler' ;
4
4
import { actions , messages } from './const' ;
5
- import { Modal , View , Text , StyleSheet , TextInput , TouchableOpacity , Platform , PixelRatio , Keyboard } from 'react-native' ;
5
+ import { Modal , View , Text , StyleSheet , TextInput , TouchableOpacity , Platform , PixelRatio , Keyboard , Dimensions } from 'react-native' ;
6
6
7
7
const injectScript = `
8
8
(function () {
9
9
${ InjectedMessageHandler }
10
10
}());
11
11
` ;
12
12
13
- const PlatfomIOS = Platform . OS === 'ios' ;
13
+ const PlatformIOS = Platform . OS === 'ios' ;
14
14
15
15
export default class RichTextEditor extends Component {
16
16
static propTypes = {
@@ -43,7 +43,7 @@ export default class RichTextEditor extends Component {
43
43
}
44
44
45
45
componentWillMount ( ) {
46
- if ( PlatfomIOS ) {
46
+ if ( PlatformIOS ) {
47
47
this . keyboardEventListeners = [
48
48
Keyboard . addListener ( 'keyboardWillShow' , this . _onKeyboardWillShow ) ,
49
49
Keyboard . addListener ( 'keyboardWillHide' , this . _onKeyboardWillHide )
@@ -66,12 +66,24 @@ export default class RichTextEditor extends Component {
66
66
if ( this . state . keyboardHeight === newKeyboardHeight ) {
67
67
return ;
68
68
}
69
+ if ( newKeyboardHeight ) {
70
+ this . setEditorAvailableHeightBasedOnKeyboardHeight ( newKeyboardHeight ) ;
71
+ }
69
72
this . setState ( { keyboardHeight : newKeyboardHeight } ) ;
70
73
}
71
74
72
75
_onKeyboardWillHide ( event ) {
73
76
this . setState ( { keyboardHeight : 0 } ) ;
74
77
}
78
+
79
+ setEditorAvailableHeightBasedOnKeyboardHeight ( keyboardHeight ) {
80
+ const { top = 0 , bottom = 0 } = this . props . contentInset ;
81
+ const { marginTop = 0 , marginBottom = 0 } = this . props . style ;
82
+ const spacing = marginTop + marginBottom + top + bottom ;
83
+
84
+ const editorAvailableHeight = Dimensions . get ( 'window' ) . height - keyboardHeight - spacing ;
85
+ this . setEditorHeight ( editorAvailableHeight ) ;
86
+ }
75
87
76
88
onBridgeMessage ( str ) {
77
89
try {
@@ -177,7 +189,7 @@ export default class RichTextEditor extends Component {
177
189
onRequestClose = { ( ) => this . setState ( { showLinkDialog : false } ) }
178
190
>
179
191
< View style = { styles . modal } >
180
- < View style = { [ styles . innerModal , { marginBottom : PlatfomIOS ? this . state . keyboardHeight : 0 } ] } >
192
+ < View style = { [ styles . innerModal , { marginBottom : PlatformIOS ? this . state . keyboardHeight : 0 } ] } >
181
193
< Text style = { styles . inputTitle } > Title</ Text >
182
194
< View style = { styles . inputWrapper } >
183
195
< TextInput
@@ -197,7 +209,7 @@ export default class RichTextEditor extends Component {
197
209
autoCorrect = { false }
198
210
/>
199
211
</ View >
200
- { PlatfomIOS && < View style = { styles . lineSeparator } /> }
212
+ { PlatformIOS && < View style = { styles . lineSeparator } /> }
201
213
{ this . _renderModalButtons ( ) }
202
214
</ View >
203
215
</ View >
@@ -216,11 +228,11 @@ export default class RichTextEditor extends Component {
216
228
217
229
_renderModalButtons ( ) {
218
230
const insertUpdateDisabled = this . state . linkTitle . trim ( ) . length <= 0 || this . state . linkUrl . trim ( ) . length <= 0 ;
219
- const containerPlatformStyle = PlatfomIOS ? { justifyContent : 'space-between' } : { paddingTop : 15 } ;
220
- const buttonPlatformStyle = PlatfomIOS ? { flex : 1 , height : 45 , justifyContent : 'center' } : { } ;
231
+ const containerPlatformStyle = PlatformIOS ? { justifyContent : 'space-between' } : { paddingTop : 15 } ;
232
+ const buttonPlatformStyle = PlatformIOS ? { flex : 1 , height : 45 , justifyContent : 'center' } : { } ;
221
233
return (
222
234
< View style = { [ { alignSelf : 'stretch' , flexDirection : 'row' } , containerPlatformStyle ] } >
223
- { ! PlatfomIOS && < View style = { { flex : 1 } } /> }
235
+ { ! PlatformIOS && < View style = { { flex : 1 } } /> }
224
236
< TouchableOpacity
225
237
onPress = { ( ) => this . _hideModal ( ) }
226
238
style = { buttonPlatformStyle }
@@ -254,16 +266,15 @@ export default class RichTextEditor extends Component {
254
266
}
255
267
256
268
_upperCaseButtonTextIfNeeded ( buttonText ) {
257
- return PlatfomIOS ? buttonText : buttonText . toUpperCase ( ) ;
269
+ return PlatformIOS ? buttonText : buttonText . toUpperCase ( ) ;
258
270
}
259
271
260
272
render ( ) {
261
273
//in release build, external html files in Android can't be required, so they must be placed in the assets folder and accessed via uri
262
- const pageSource = PlatfomIOS ? require ( './editor.html' ) : { uri : 'file:///android_asset/editor.html' } ;
274
+ const pageSource = PlatformIOS ? require ( './editor.html' ) : { uri : 'file:///android_asset/editor.html' } ;
263
275
return (
264
276
< View style = { { flex : 1 } } >
265
277
< WebViewBridge
266
- style = { { flex : 1 } }
267
278
{ ...this . props }
268
279
hideKeyboardAccessoryView = { true }
269
280
keyboardDisplayRequiresUserAction = { false }
@@ -492,6 +503,15 @@ export default class RichTextEditor extends Component {
492
503
493
504
init ( ) {
494
505
this . _sendAction ( actions . init ) ;
506
+ this . setPlatform ( ) ;
507
+ }
508
+
509
+ setEditorHeight ( height ) {
510
+ this . _sendAction ( actions . setEditorHeight , height ) ;
511
+ }
512
+
513
+ setPlatform ( ) {
514
+ this . _sendAction ( actions . setPlatform , Platform . OS ) ;
495
515
}
496
516
497
517
async getTitleHtml ( ) {
@@ -571,12 +591,12 @@ const styles = StyleSheet.create({
571
591
innerModal : {
572
592
backgroundColor : 'rgba(255, 255, 255, 0.9)' ,
573
593
paddingTop : 20 ,
574
- paddingBottom : PlatfomIOS ? 0 : 20 ,
594
+ paddingBottom : PlatformIOS ? 0 : 20 ,
575
595
paddingLeft : 20 ,
576
596
paddingRight : 20 ,
577
597
alignSelf : 'stretch' ,
578
598
margin : 40 ,
579
- borderRadius : PlatfomIOS ? 8 : 2
599
+ borderRadius : PlatformIOS ? 8 : 2
580
600
} ,
581
601
button : {
582
602
fontSize : 16 ,
@@ -587,13 +607,13 @@ const styles = StyleSheet.create({
587
607
marginTop : 5 ,
588
608
marginBottom : 10 ,
589
609
borderBottomColor : '#4a4a4a' ,
590
- borderBottomWidth : PlatfomIOS ? 1 / PixelRatio . get ( ) : 0
610
+ borderBottomWidth : PlatformIOS ? 1 / PixelRatio . get ( ) : 0
591
611
} ,
592
612
inputTitle : {
593
613
color : '#4a4a4a'
594
614
} ,
595
615
input : {
596
- height : PlatfomIOS ? 20 : 40 ,
616
+ height : PlatformIOS ? 20 : 40 ,
597
617
paddingTop : 0
598
618
} ,
599
619
lineSeparator : {
0 commit comments