Module.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React, {Fragment} from 'react';
  2. import { View } from 'react-native';
  3. import { Resolver } from './Types';
  4. // EventSystem
  5. export default class Module extends React.Component{
  6. constructor(props) {
  7. super(props);
  8. let {
  9. ModuleID,
  10. EventSystem
  11. } = props;
  12. let eventName = ModuleID + "HitCheck"
  13. EventSystem && EventSystem.on(eventName, ({x,y}) => {
  14. return true;
  15. });
  16. this.isTemplate = false
  17. //console.log("GEN EV: " , eventName, EventSystem);
  18. this._containerStyle = {
  19. marginLeft: 24,
  20. marginRight: 24
  21. }
  22. }
  23. getId() {
  24. return this.props.ModuleID;
  25. }
  26. renderModule(ctor, namespace = "default", props = {}) {
  27. let VS = this.props.CoreSystem.ViewSystem;
  28. if(!this.props.CoreSystem.ModuleSystem.get(ctor, namespace)) return null;
  29. return VS.renderModule({
  30. value: ctor,
  31. namespace,
  32. props
  33. }, this.getId() +"C"+ (this.counter++));
  34. }
  35. createAction(action) {
  36. if(!this.props.CoreSystem) {
  37. console.warning("This module was constructed without a CoreSystem");
  38. return;
  39. }
  40. return this.props.CoreSystem.ActionSystem.createAction(action);
  41. }
  42. setContainerStyle(style) {
  43. this._containerStyle = style;
  44. }
  45. display() {
  46. throw new Error("You must extend this base Module and override display method!");
  47. }
  48. render() {
  49. this.counter = 0;
  50. return <View ModuleID={this.props.ModuleID} style={[{overflow:'hidden'}]} MY_WRAPPER_FROM_BASE_MODULE={true}>
  51. {this.display()}
  52. </View>
  53. // throw new Error("You must extend this base Module and override render method!");
  54. }
  55. getProps() {
  56. return Resolver(this.constructor.Inputs, this.props);
  57. }
  58. }