MainBar.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import React from 'react';
  2. import {StyleSheet, View, Text , Button } from 'react-native';
  3. import { Icon } from 'react-native-elements'
  4. import { TextInput } from 'react-native';
  5. import BaseSystem from './System'
  6. import { Ionicons } from '@expo/vector-icons';
  7. class Menu extends BaseSystem {
  8. constructor() {
  9. super();
  10. this.items = [];
  11. }
  12. addItem(item) {
  13. this.items.push(item);
  14. return this;
  15. }
  16. show() { this.visible = true; this.forceUpdate() }
  17. hide() { this.visible = false; this.forceUpdate() }
  18. toggle() { this.visible = !this.visible; this.forceUpdate() }
  19. render() {
  20. return this.visible ? <div style={{position:'relative', left: 0, top: 50}}
  21. onMouseLeave={() => this.hide()}>
  22. <View style={styles.menu}>
  23. {this.items.map((item) => {
  24. let {
  25. text,
  26. ...rest
  27. } = item;
  28. return <View style={{cursor: 'pointer'}} {...rest}>
  29. <Text>{item.text}</Text>
  30. </View>
  31. })}
  32. </View>
  33. </div> : null;
  34. }
  35. }
  36. export default class MainBar extends BaseSystem {
  37. constructor(CS){
  38. super();
  39. this.__save = null
  40. this.CoreSystem = CS;
  41. this.Menu = new Menu();
  42. this.Menu.addItem({
  43. text: "New page",
  44. onClick: () => this.createPage()
  45. }).addItem({
  46. text: "Save",
  47. onClick: () => this.save()
  48. }).addItem({
  49. text: "Export",
  50. onClick: () => this.export()
  51. }).onUpdate(() => this.forceUpdate());
  52. }
  53. export() {
  54. let json = JSON.stringify(this.CoreSystem.export());
  55. console.log(json);
  56. }
  57. onSave(fn){
  58. this.__save = fn;
  59. }
  60. save(){
  61. this.__save && this.__save();
  62. }
  63. triggerSave(){
  64. this.save();
  65. }
  66. createPage() {
  67. // think!
  68. // Create a new page on CoreSystem
  69. // switch to it as active view
  70. // Decide how page switching works
  71. }
  72. none(){
  73. }
  74. toggleMenu() {
  75. this.Menu.toggle();
  76. }
  77. showMenu() {
  78. this.Menu.show();
  79. }
  80. hideMenu() {
  81. this.Menu.hide();
  82. }
  83. render(){
  84. return (
  85. <View style={styles.container}>
  86. <View style={ styles.innerContainer }>
  87. <Text style={styles.item}>
  88. <Icon
  89. name='menu'
  90. color="#606060"
  91. onPress={(e) => this.toggleMenu()}
  92. />
  93. </Text>
  94. <Text style={styles.item}>
  95. <Icon
  96. name='home'
  97. color="#606060"
  98. />
  99. </Text>
  100. </View>
  101. <View style={ styles.innerContainer }>
  102. <Text style={[styles.item, {fontSize: 18, lineHeight: 24}]}
  103. onPress={(e) => this.triggerSave()}
  104. title="Save"
  105. color="#606060"
  106. >Save</Text>
  107. <Text style={[styles.item, {fontSize: 18, lineHeight: 24}]}
  108. onPress={(e) => this.export()}
  109. title="Export"
  110. color="#606060"
  111. >Export</Text>
  112. <Text style={[styles.item, {fontSize: 18, lineHeight: 24}]}>
  113. Giorgos Markou
  114. </Text>
  115. <Text style={styles.item}>
  116. <Icon name="account-circle" color="#606060"/>
  117. </Text>
  118. </View>
  119. {this.Menu.render()}
  120. </View>)
  121. }
  122. }
  123. const styles = StyleSheet.create({
  124. container:{
  125. flex:1,
  126. paddingRight:8,
  127. paddingLeft:8,
  128. paddingTop: 8,
  129. paddingBottom: 8,
  130. flexDirection:'row',
  131. justifyContent: 'space-between'
  132. },
  133. innerContainer: {
  134. flexDirection: 'row',
  135. paddingTop: 4,
  136. paddingLeft: 0,
  137. paddingRight: 0,
  138. paddingBottom: 4
  139. },
  140. item: {
  141. paddingLeft: 8,
  142. paddingRight: 8,
  143. fontFamily: 'thin'
  144. },
  145. menu: {
  146. height:100,
  147. width: 200,
  148. backgroundColor: 'gray'
  149. }
  150. })