fixed keyboardavoding & style

This commit is contained in:
ue 2018-10-20 01:27:42 +03:00
parent 4c713b9363
commit 8186dff487
8 changed files with 114 additions and 120 deletions

View File

@ -1,13 +1,9 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { View, Text } from 'react-native';
// Constants // Constants
// Components // Components
import { MarkdownEditor } from '../../../markdownEditor'; import { MarkdownEditor } from '../../../markdownEditor';
// Styles
import styles from './textAreaStyles';
export default class TextAreaView extends Component { export default class TextAreaView extends Component {
/* Props /* Props
* ------------------------------------------------ * ------------------------------------------------
@ -22,18 +18,8 @@ export default class TextAreaView extends Component {
// Component Life Cycles // Component Life Cycles
// Component Functions // Component Functions
defaultMarkdownButton = ({ item, getState, setState }) => <Text>ugur</Text>;
render() { render() {
return ( return <MarkdownEditor {...this.props} />;
<View style={styles.container}>
<MarkdownEditor
placeholderString="ugur"
// markdownButton={e => this.defaultMarkdownButton(e)}
placeholder="sss"
{...this.props}
/>
</View>
);
} }
} }

View File

@ -3,7 +3,7 @@ import EStyleSheet from 'react-native-extended-stylesheet';
export default EStyleSheet.create({ export default EStyleSheet.create({
container: { container: {
flexDirection: 'row', flexDirection: 'row',
backgroundColor: 'red', backgroundColor: '$white',
alignItems: 'center', alignItems: 'center',
height: 48, height: 48,
shadowOpacity: 0.2, shadowOpacity: 0.2,

View File

@ -1,33 +1,30 @@
import EStyleSheet from 'react-native-extended-stylesheet'; import EStyleSheet from 'react-native-extended-stylesheet';
export default EStyleSheet.create({ export default EStyleSheet.create({
textWrapper: { container: {
flex: 1,
flexDirection: 'column',
fontSize: 16,
},
inlinePadding: {
padding: 8,
},
wrapper: {
flex: 1, flex: 1,
flexDirection: 'column', flexDirection: 'column',
alignItems: 'stretch', alignItems: 'stretch',
backgroundColor: '$white', backgroundColor: '$white',
}, },
// markdownStyles: { textWrapper: {
// heading1: { flex: 1,
// fontSize: 24, flexDirection: 'column',
// color: 'purple', fontSize: 12,
// }, marginVertical: 16,
// link: { paddingHorizontal: 16,
// color: 'pink', },
// }, inlinePadding: {
// mailTo: { padding: 8,
// color: 'orange', },
// }, editorButtons: {
// text: { flexDirection: 'row',
// color: '#555555', backgroundColor: '$white',
// }, alignItems: 'center',
// }, height: 48,
shadowOpacity: 0.2,
shadowOffset: {
height: 1.5,
},
},
}); });

View File

@ -1,29 +1,23 @@
import React from 'react'; import React, { Component } from 'react';
import { import {
View, TextInput, Platform, KeyboardAvoidingView, ScrollView, View,
TextInput,
KeyboardAvoidingView,
ScrollView,
TouchableOpacity,
Text,
FlatList,
} from 'react-native'; } from 'react-native';
import { MarkdownView } from 'react-native-markdown-view'; import { MarkdownView } from 'react-native-markdown-view';
import { renderFormatButtons } from './renderButtons'; // Components
import Formats from './formats/formats';
// Styles
import styles from './markdownEditorStyles'; import styles from './markdownEditorStyles';
import previewStyles from './markdownPreviewStyles';
const markdownStyles = { export default class MarkdownEditorView extends Component {
heading1: {
fontSize: 24,
color: 'purple',
},
link: {
color: 'pink',
},
mailTo: {
color: 'orange',
},
text: {
color: '#555555',
},
};
export default class MarkdownEditorView extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
@ -32,13 +26,11 @@ export default class MarkdownEditorView extends React.Component {
}; };
} }
textInput: TextInput;
componentDidMount() { componentDidMount() {
this.textInput.focus(); this.textInput.focus();
} }
changeText = (input: string) => { changeText = (input) => {
const { onMarkdownChange } = this.props; const { onMarkdownChange } = this.props;
this.setState({ text: input }); this.setState({ text: input });
@ -48,13 +40,13 @@ export default class MarkdownEditorView extends React.Component {
} }
}; };
onSelectionChange = (event) => { _handleOnSelectionChange = (event) => {
this.setState({ this.setState({
selection: event.nativeEvent.selection, selection: event.nativeEvent.selection,
}); });
}; };
getState = () => { _getState = () => {
this.setState({ this.setState({
selection: { selection: {
start: 1, start: 1,
@ -64,13 +56,13 @@ export default class MarkdownEditorView extends React.Component {
return this.state; return this.state;
}; };
renderPreview = () => { _renderPreview = () => {
const { text } = this.state; const { text } = this.state;
return ( return (
<View style={styles.textWrapper}> <View style={styles.textWrapper}>
<ScrollView removeClippedSubviews> <ScrollView removeClippedSubviews>
<MarkdownView styles={markdownStyles}> <MarkdownView styles={previewStyles}>
{text === '' ? 'There is nothing to preview here' : text} {text === '' ? 'There is nothing to preview here' : text}
</MarkdownView> </MarkdownView>
</ScrollView> </ScrollView>
@ -78,49 +70,55 @@ export default class MarkdownEditorView extends React.Component {
); );
}; };
render() { _renderMarkupButton = ({ item, getState, setState }) => (
const { <TouchableOpacity onPress={() => item.onPress({ getState, setState, item })}>
Formats, markdownButton, placeHolder, isPreviewActive, <Text style={item.style}>{item.title}</Text>
} = this.props; </TouchableOpacity>
const { text, selection } = this.state; );
return (
<View style={styles.wrapper}>
{!isPreviewActive ? (
<View
style={styles.textWrapper}
> _renderEditorButtons = ({ getState, setState }) => (
<View style={styles.editorButtons}>
<FlatList
data={Formats}
keyboardShouldPersistTaps="always"
renderItem={({ item }) => this._renderMarkupButton({ item, getState, setState })}
horizontal
/>
</View>
);
render() {
const { placeHolder, isPreviewActive } = this.props;
const { text, selection } = this.state;
return (
<KeyboardAvoidingView style={styles.container} behavior="padding">
{!isPreviewActive ? (
<TextInput <TextInput
style={styles.textWrapper} style={styles.textWrapper}
multiline multiline
underlineColorAndroid="transparent" underlineColorAndroid="transparent"
onChangeText={this.changeText} onChangeText={this.changeText}
onSelectionChange={this.onSelectionChange} onSelectionChange={this._handleOnSelectionChange}
value={text} value={text}
placeholder={placeHolder} placeholder={placeHolder}
placeholderTextColor="#c1c5c7"
ref={textInput => (this.textInput = textInput)} ref={textInput => (this.textInput = textInput)}
selection={selection} selection={selection}
selectionColor="#357ce6" selectionColor="#357ce6"
/> />
</View>
) : ( ) : (
this.renderPreview() this._renderPreview()
)} )}
<KeyboardAvoidingView behavior="padding">
{!isPreviewActive {!isPreviewActive
&& renderFormatButtons( && this._renderEditorButtons({
{ getState: this._getState,
getState: this.getState,
setState: (state, callback) => { setState: (state, callback) => {
this.textInput.focus(); this.textInput.focus();
this.setState(state, callback); this.setState(state, callback);
}, },
}, })}
Formats,
markdownButton,
)}
</KeyboardAvoidingView> </KeyboardAvoidingView>
</View>
); );
} }
} }

View File

@ -0,0 +1,16 @@
export const markdownPreviewStyles = {
heading1: {
fontSize: 24,
color: 'red',
backgroundColor: 'red',
},
link: {
color: 'pink',
},
mailTo: {
color: 'orange',
},
text: {
color: '#555555',
},
};

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { import {
FlatList, TouchableOpacity, Text, View, KeyboardAvoidingView, FlatList, TouchableOpacity, Text, View,
} from 'react-native'; } from 'react-native';
import Formats from './formats/formats'; import Formats from './formats/formats';
@ -16,8 +16,7 @@ const defaultMarkdownButton = ({ item, getState, setState }) => (
</TouchableOpacity> </TouchableOpacity>
); );
export const renderFormatButtons = ({ getState, setState }, formats, markdownButton) => ( export const renderEditorButtons = ({ getState, setState }, formats, markdownButton) => (
<KeyboardAvoidingView behavior="padding">
<View style={styles.container}> <View style={styles.container}>
<FlatList <FlatList
data={formats || Formats} data={formats || Formats}
@ -29,5 +28,4 @@ export const renderFormatButtons = ({ getState, setState }, formats, markdownBut
horizontal horizontal
/> />
</View> </View>
</KeyboardAvoidingView>
); );

View File

@ -2,7 +2,6 @@ import EStyleSheet from 'react-native-extended-stylesheet';
export default EStyleSheet.create({ export default EStyleSheet.create({
containerHorizontal16: { containerHorizontal16: {
flex: 1,
paddingHorizontal: 16, paddingHorizontal: 16,
}, },
defaultContainer: { defaultContainer: {

View File

@ -43,8 +43,8 @@ export class EditorScreen extends Component {
<View style={globalStyles.containerHorizontal16}> <View style={globalStyles.containerHorizontal16}>
<TitleArea /> <TitleArea />
<TagArea /> <TagArea />
<TextArea isPreviewActive={isPreviewActive} />
</View> </View>
<TextArea placeHolder="What would you like to write about today?" isPreviewActive={isPreviewActive} />
</View> </View>
); );
} }