Alignment.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. alignSelf(i) {
  28. let style = { alignSelf: this.getStyle(i) };
  29. this.props.onSelect && this.props.onSelect(style)
  30. }
  31. render() {
  32. let iconStyle = styles.iconStyle;
  33. return ([
  34. <View style={styles.container} key={'align'}>
  35. <Icon name="format-align-left" iconStyle={iconStyle} onClick={() => this.set(0)}/>
  36. <Icon name="format-align-center" iconStyle={iconStyle} onClick={() => this.set(1)}/>
  37. <Icon name="format-align-right" iconStyle={iconStyle} onClick={() => this.set(2)}/>
  38. <Icon name="format-align-justify" iconStyle={iconStyle} onClick={() => this.set(3)}/>
  39. </View>,
  40. <View style={styles.container} key={'justify'}>
  41. <Icon name="vertical-align-top" iconStyle={iconStyle} onClick={() => this.justify(0)}/>
  42. <Icon name="vertical-align-center" iconStyle={iconStyle} onClick={() => this.justify(1)}/>
  43. <Icon name="vertical-align-bottom" iconStyle={iconStyle} onClick={() => this.justify(2)}/>
  44. <Icon name="toc" iconStyle={iconStyle} onClick={() => this.justify(4)}/>
  45. <Icon name="view-headline" iconStyle={iconStyle} onClick={() => this.justify(5)}/>
  46. </View>,
  47. <View style={styles.container} key={'alignSelf'}>
  48. <Icon name="vertical-align-top" iconStyle={iconStyle} onClick={() => this.alignSelf(0)}/>
  49. <Icon name="vertical-align-center" iconStyle={iconStyle} onClick={() => this.alignSelf(1)}/>
  50. <Icon name="vertical-align-bottom" iconStyle={iconStyle} onClick={() => this.alignSelf(2)}/>
  51. <Icon name="toc" iconStyle={iconStyle} onClick={() => this.alignSelf(3)}/>
  52. <Icon name="view-headline" iconStyle={iconStyle} onClick={() => this.alignSelf(6)}/>
  53. </View>
  54. ]
  55. );
  56. }
  57. }
  58. const styles = StyleSheet.create({
  59. container:{
  60. padding:10,
  61. flexDirection: 'row',
  62. justifyContent: 'space-around',
  63. borderBottomColor: '#B4B4B4',
  64. borderBottomWidth: 1
  65. },
  66. defaultInput: {
  67. marginTop:6,
  68. borderWidth:1,
  69. width:200
  70. },
  71. title: {
  72. },
  73. iconStyle: {
  74. fontSize: 18,
  75. opacity: 0.6,
  76. cursor: 'pointer'
  77. }
  78. })