MainBar.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. <Button
  86. color="#f1f1f1"
  87. title={<Icon name='menu'
  88. color="#606060"
  89. />}
  90. onPress={(e) => this.toggleMenu()}
  91. />
  92. <Button
  93. color="#f1f1f1"
  94. title={<Icon name='home'
  95. color="#606060"
  96. />}
  97. />
  98. <Text style={{height:30,width:80,fontSize:11,marginTop:6}}>
  99. <Button
  100. onPress={(e) => this.triggerSave()}
  101. title="Save"
  102. color="#606060"
  103. />
  104. </Text>
  105. <Text style={{height:30,width:80,fontSize:11,marginTop:6}}>
  106. <Button
  107. onPress={(e) => this.export()}
  108. title="Export"
  109. color="#606060"
  110. />
  111. </Text>
  112. {this.Menu.render()}
  113. </View>)
  114. }
  115. }
  116. const styles = StyleSheet.create({
  117. container:{
  118. flex:1,
  119. paddingRight:25,
  120. marginLeft:5,
  121. flexDirection:'row',
  122. },
  123. menu: {
  124. height:100,
  125. width: 200,
  126. backgroundColor: 'gray'
  127. }
  128. })