mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-26 17:25:13 +03:00
fixed keyboardavoding & style
This commit is contained in:
parent
4c713b9363
commit
8186dff487
@ -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>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
@ -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,
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
@ -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 {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_renderMarkupButton = ({ item, getState, setState }) => (
|
||||||
|
<TouchableOpacity onPress={() => item.onPress({ getState, setState, item })}>
|
||||||
|
<Text style={item.style}>{item.title}</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
);
|
||||||
|
|
||||||
|
_renderEditorButtons = ({ getState, setState }) => (
|
||||||
|
<View style={styles.editorButtons}>
|
||||||
|
<FlatList
|
||||||
|
data={Formats}
|
||||||
|
keyboardShouldPersistTaps="always"
|
||||||
|
renderItem={({ item }) => this._renderMarkupButton({ item, getState, setState })}
|
||||||
|
horizontal
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const { placeHolder, isPreviewActive } = this.props;
|
||||||
Formats, markdownButton, placeHolder, isPreviewActive,
|
|
||||||
} = this.props;
|
|
||||||
const { text, selection } = this.state;
|
const { text, selection } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.wrapper}>
|
<KeyboardAvoidingView style={styles.container} behavior="padding">
|
||||||
{!isPreviewActive ? (
|
{!isPreviewActive ? (
|
||||||
<View
|
<TextInput
|
||||||
style={styles.textWrapper}
|
style={styles.textWrapper}
|
||||||
|
multiline
|
||||||
>
|
underlineColorAndroid="transparent"
|
||||||
<TextInput
|
onChangeText={this.changeText}
|
||||||
style={styles.textWrapper}
|
onSelectionChange={this._handleOnSelectionChange}
|
||||||
multiline
|
value={text}
|
||||||
underlineColorAndroid="transparent"
|
placeholder={placeHolder}
|
||||||
onChangeText={this.changeText}
|
placeholderTextColor="#c1c5c7"
|
||||||
onSelectionChange={this.onSelectionChange}
|
ref={textInput => (this.textInput = textInput)}
|
||||||
value={text}
|
selection={selection}
|
||||||
placeholder={placeHolder}
|
selectionColor="#357ce6"
|
||||||
ref={textInput => (this.textInput = textInput)}
|
/>
|
||||||
selection={selection}
|
|
||||||
selectionColor="#357ce6"
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
) : (
|
) : (
|
||||||
this.renderPreview()
|
this._renderPreview()
|
||||||
)}
|
)}
|
||||||
<KeyboardAvoidingView behavior="padding">
|
{!isPreviewActive
|
||||||
{!isPreviewActive
|
&& this._renderEditorButtons({
|
||||||
&& renderFormatButtons(
|
getState: this._getState,
|
||||||
{
|
setState: (state, callback) => {
|
||||||
getState: this.getState,
|
this.textInput.focus();
|
||||||
setState: (state, callback) => {
|
this.setState(state, callback);
|
||||||
this.textInput.focus();
|
},
|
||||||
this.setState(state, callback);
|
})}
|
||||||
},
|
</KeyboardAvoidingView>
|
||||||
},
|
|
||||||
Formats,
|
|
||||||
markdownButton,
|
|
||||||
)}
|
|
||||||
</KeyboardAvoidingView>
|
|
||||||
</View>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
src/components/markdownEditor/view/markdownPreviewStyles.js
Normal file
16
src/components/markdownEditor/view/markdownPreviewStyles.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
export const markdownPreviewStyles = {
|
||||||
|
heading1: {
|
||||||
|
fontSize: 24,
|
||||||
|
color: 'red',
|
||||||
|
backgroundColor: 'red',
|
||||||
|
},
|
||||||
|
link: {
|
||||||
|
color: 'pink',
|
||||||
|
},
|
||||||
|
mailTo: {
|
||||||
|
color: 'orange',
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
color: '#555555',
|
||||||
|
},
|
||||||
|
};
|
@ -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,18 +16,16 @@ 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}
|
keyboardShouldPersistTaps="always"
|
||||||
keyboardShouldPersistTaps="always"
|
renderItem={({ item, index }) => (markdownButton
|
||||||
renderItem={({ item, index }) => (markdownButton
|
? markdownButton({ item, getState, setState })
|
||||||
? markdownButton({ item, getState, setState })
|
: defaultMarkdownButton({ item, getState, setState }))
|
||||||
: defaultMarkdownButton({ item, getState, setState }))
|
}
|
||||||
}
|
horizontal
|
||||||
horizontal
|
/>
|
||||||
/>
|
</View>
|
||||||
</View>
|
|
||||||
</KeyboardAvoidingView>
|
|
||||||
);
|
);
|
||||||
|
@ -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: {
|
||||||
|
@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user