MainBar.js 2.8 KB

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