MainBar.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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:'absolute', 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(){
  37. super();
  38. this.__save = null
  39. this.Menu = new Menu();
  40. this.Menu.addItem({
  41. text: "New page",
  42. onClick: () => this.createPage()
  43. }).addItem({
  44. text: "Save",
  45. onClick: () => this.save()
  46. }).onUpdate(() => this.forceUpdate());
  47. }
  48. onSave(fn){
  49. this.__save = fn;
  50. }
  51. save(){
  52. this.__save && this.__save();
  53. }
  54. triggerSave(){
  55. this.save();
  56. }
  57. createPage() {
  58. // think!
  59. // Create a new page on CoreSystem
  60. // switch to it as active view
  61. // Decide how page switching works
  62. }
  63. none(){
  64. }
  65. toggleMenu() {
  66. this.Menu.toggle();
  67. }
  68. showMenu() {
  69. this.Menu.show();
  70. }
  71. hideMenu() {
  72. this.Menu.hide();
  73. }
  74. render(){
  75. return (
  76. <View style={styles.container}>
  77. <Button
  78. color="#f1f1f1"
  79. title={<Icon name='menu'
  80. color="#606060"
  81. />}
  82. onPress={(e) => this.toggleMenu()}
  83. />
  84. <Button
  85. color="#f1f1f1"
  86. title={<Icon name='home'
  87. color="#606060"
  88. />}
  89. />
  90. <Text style={{height:30,width:80,fontSize:11,marginTop:6}}>
  91. <Button
  92. onPress={(e) => this.triggerSave()}
  93. title="Save"
  94. color="#606060"
  95. />
  96. </Text>
  97. {this.Menu.render()}
  98. </View>)
  99. }
  100. }
  101. const styles = StyleSheet.create({
  102. container:{
  103. flex:1,
  104. paddingRight:25,
  105. flexDirection:'row',
  106. },
  107. menu: {
  108. height:100,
  109. width: 200,
  110. backgroundColor: 'gray'
  111. }
  112. })