@@ -2,15 +2,15 @@ import React, {Component, PropTypes} from 'react';
22import WebViewBridge from 'react-native-webview-bridge-updated' ;
33import { InjectedMessageHandler } from './WebviewMessageHandler' ;
44import { 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' ;
66
77const injectScript = `
88 (function () {
99 ${ InjectedMessageHandler }
1010 }());
1111` ;
1212
13- const PlatfomIOS = Platform . OS === 'ios' ;
13+ const PlatformIOS = Platform . OS === 'ios' ;
1414
1515export default class RichTextEditor extends Component {
1616 static propTypes = {
@@ -43,7 +43,7 @@ export default class RichTextEditor extends Component {
4343 }
4444
4545 componentWillMount ( ) {
46- if ( PlatfomIOS ) {
46+ if ( PlatformIOS ) {
4747 this . keyboardEventListeners = [
4848 Keyboard . addListener ( 'keyboardWillShow' , this . _onKeyboardWillShow ) ,
4949 Keyboard . addListener ( 'keyboardWillHide' , this . _onKeyboardWillHide )
@@ -66,12 +66,24 @@ export default class RichTextEditor extends Component {
6666 if ( this . state . keyboardHeight === newKeyboardHeight ) {
6767 return ;
6868 }
69+ if ( newKeyboardHeight ) {
70+ this . setEditorAvailableHeightBasedOnKeyboardHeight ( newKeyboardHeight ) ;
71+ }
6972 this . setState ( { keyboardHeight : newKeyboardHeight } ) ;
7073 }
7174
7275 _onKeyboardWillHide ( event ) {
7376 this . setState ( { keyboardHeight : 0 } ) ;
7477 }
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+ }
7587
7688 onBridgeMessage ( str ) {
7789 try {
@@ -177,7 +189,7 @@ export default class RichTextEditor extends Component {
177189 onRequestClose = { ( ) => this . setState ( { showLinkDialog : false } ) }
178190 >
179191 < 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 } ] } >
181193 < Text style = { styles . inputTitle } > Title</ Text >
182194 < View style = { styles . inputWrapper } >
183195 < TextInput
@@ -197,7 +209,7 @@ export default class RichTextEditor extends Component {
197209 autoCorrect = { false }
198210 />
199211 </ View >
200- { PlatfomIOS && < View style = { styles . lineSeparator } /> }
212+ { PlatformIOS && < View style = { styles . lineSeparator } /> }
201213 { this . _renderModalButtons ( ) }
202214 </ View >
203215 </ View >
@@ -216,11 +228,11 @@ export default class RichTextEditor extends Component {
216228
217229 _renderModalButtons ( ) {
218230 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' } : { } ;
221233 return (
222234 < View style = { [ { alignSelf : 'stretch' , flexDirection : 'row' } , containerPlatformStyle ] } >
223- { ! PlatfomIOS && < View style = { { flex : 1 } } /> }
235+ { ! PlatformIOS && < View style = { { flex : 1 } } /> }
224236 < TouchableOpacity
225237 onPress = { ( ) => this . _hideModal ( ) }
226238 style = { buttonPlatformStyle }
@@ -254,16 +266,15 @@ export default class RichTextEditor extends Component {
254266 }
255267
256268 _upperCaseButtonTextIfNeeded ( buttonText ) {
257- return PlatfomIOS ? buttonText : buttonText . toUpperCase ( ) ;
269+ return PlatformIOS ? buttonText : buttonText . toUpperCase ( ) ;
258270 }
259271
260272 render ( ) {
261273 //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' } ;
263275 return (
264276 < View style = { { flex : 1 } } >
265277 < WebViewBridge
266- style = { { flex : 1 } }
267278 { ...this . props }
268279 hideKeyboardAccessoryView = { true }
269280 keyboardDisplayRequiresUserAction = { false }
@@ -492,6 +503,15 @@ export default class RichTextEditor extends Component {
492503
493504 init ( ) {
494505 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 ) ;
495515 }
496516
497517 async getTitleHtml ( ) {
@@ -571,12 +591,12 @@ const styles = StyleSheet.create({
571591 innerModal : {
572592 backgroundColor : 'rgba(255, 255, 255, 0.9)' ,
573593 paddingTop : 20 ,
574- paddingBottom : PlatfomIOS ? 0 : 20 ,
594+ paddingBottom : PlatformIOS ? 0 : 20 ,
575595 paddingLeft : 20 ,
576596 paddingRight : 20 ,
577597 alignSelf : 'stretch' ,
578598 margin : 40 ,
579- borderRadius : PlatfomIOS ? 8 : 2
599+ borderRadius : PlatformIOS ? 8 : 2
580600 } ,
581601 button : {
582602 fontSize : 16 ,
@@ -587,13 +607,13 @@ const styles = StyleSheet.create({
587607 marginTop : 5 ,
588608 marginBottom : 10 ,
589609 borderBottomColor : '#4a4a4a' ,
590- borderBottomWidth : PlatfomIOS ? 1 / PixelRatio . get ( ) : 0
610+ borderBottomWidth : PlatformIOS ? 1 / PixelRatio . get ( ) : 0
591611 } ,
592612 inputTitle : {
593613 color : '#4a4a4a'
594614 } ,
595615 input : {
596- height : PlatfomIOS ? 20 : 40 ,
616+ height : PlatformIOS ? 20 : 40 ,
597617 paddingTop : 0
598618 } ,
599619 lineSeparator : {
0 commit comments