Alignment.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React, { useState } from 'react';
  2. import {View , Text, TextInput, Button,StyleSheet} from 'react-native';
  3. import { Icon } from 'react-native-elements'
  4. export default class Alignment extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. }
  8. getStyle(i) {
  9. switch(i) {
  10. case 0: return 'flex-start'
  11. case 1: return 'center'
  12. case 2: return 'flex-end'
  13. case 3: return 'stretch'
  14. case 4: return 'space-around'
  15. case 5: return 'space-between'
  16. case 6: return 'baseline'
  17. }
  18. }
  19. set(i) {
  20. let style = { alignItems: this.getStyle(i) };
  21. this.props.onSelect && this.props.onSelect(style)
  22. }
  23. justify(i) {
  24. let style = { justifyContent: this.getStyle(i) };
  25. this.props.onSelect && this.props.onSelect(style)
  26. }
  27. render() {
  28. let iconStyle = styles.iconStyle;
  29. return ([
  30. <View style={styles.container} key={'align'}>
  31. <Icon name="format-align-left" iconStyle={iconStyle} onClick={() => this.set(0)}/>
  32. <Icon name="format-align-center" iconStyle={iconStyle} onClick={() => this.set(1)}/>
  33. <Icon name="format-align-right" iconStyle={iconStyle} onClick={() => this.set(2)}/>
  34. <Icon name="format-align-justify" iconStyle={iconStyle} onClick={() => this.set(3)}/>
  35. </View>,
  36. <View style={styles.container} key={'justify'}>
  37. <Icon name="vertical-align-top" iconStyle={iconStyle} onClick={() => this.justify(0)}/>
  38. <Icon name="vertical-align-center" iconStyle={iconStyle} onClick={() => this.justify(1)}/>
  39. <Icon name="vertical-align-bottom" iconStyle={iconStyle} onClick={() => this.justify(2)}/>
  40. <Icon name="toc" iconStyle={iconStyle} onClick={() => this.justify(4)}/>
  41. <Icon name="view-headline" iconStyle={iconStyle} onClick={() => this.justify(5)}/>
  42. </View>
  43. ]
  44. );
  45. }
  46. }
  47. const styles = StyleSheet.create({
  48. container:{
  49. padding:10,
  50. flexDirection: 'row',
  51. justifyContent: 'space-around',
  52. borderBottomColor: '#B4B4B4',
  53. borderBottomWidth: 1
  54. },
  55. defaultInput: {
  56. marginTop:6,
  57. borderWidth:1,
  58. width:200
  59. },
  60. title: {
  61. },
  62. iconStyle: {
  63. fontSize: 18,
  64. opacity: 0.6,
  65. cursor: 'pointer'
  66. }
  67. })