How to use the hyperview/src/services/namespaces.HYPERVIEW function in hyperview

To help you get started, we’ve selected a few hyperview examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Instawork / hyperview / src / services / stylesheets / index.js View on Github external
function createStylesheet(
  document: Document,
  modifiers = {},
): StyleSheetType<*> {
  const styles = getFirstTag(document, 'styles');
  const stylesheet = {};
  if (styles) {
    const styleElements = styles.getElementsByTagNameNS(
      Namespaces.HYPERVIEW,
      'style',
    );

    for (let i = 0; i < styleElements.length; i += 1) {
      const styleElement = styleElements.item(i);
      const hasModifier =
        styleElement.parentNode &&
        styleElement.parentNode.tagName === 'modifier';

      let styleId = styleElement.getAttribute('id');
      if (hasModifier) {
        // TODO(adam): Use less hacky way to get id of parent style element.
        styleId = styleElement.parentNode.parentNode.getAttribute('id');
      }

      // This must be a root style or a modifier style
github Instawork / hyperview / src / services / render / index.js View on Github external
onUpdate: HvComponentOnUpdate,
  options: HvComponentOptions,
) => {
  if (element.nodeType === NODE_TYPE.ELEMENT_NODE) {
    // Hidden elements don't get rendered
    if (element.getAttribute('hide') === 'true') {
      return null;
    }
  }
  if (element.nodeType === NODE_TYPE.COMMENT_NODE) {
    // XML comments don't get rendered.
    return null;
  }
  if (
    element.nodeType === NODE_TYPE.ELEMENT_NODE &&
    element.namespaceURI === Namespaces.HYPERVIEW
  ) {
    switch (element.localName) {
      case LOCAL_NAME.BODY:
      case LOCAL_NAME.VIEW:
      case LOCAL_NAME.FORM:
      case LOCAL_NAME.HEADER:
      case LOCAL_NAME.ITEM:
      case LOCAL_NAME.SECTION_TITLE:
        // TODO: Create HvView component
        return view(element, stylesheets, onUpdate, options);
      case LOCAL_NAME.TEXT:
        // TODO: Create HvText component
        return text(element, stylesheets, onUpdate, options);
      case LOCAL_NAME.BEHAVIOR:
      case LOCAL_NAME.MODIFIER:
      case LOCAL_NAME.STYLES:
github Instawork / hyperview / src / services / navigation / index.js View on Github external
href: string,
    action: NavAction,
    element: Element,
    opts: BehaviorOptions,
  ): void => {
    const { showIndicatorId, delay } = opts;
    const formData: ?FormData = getFormData(element);

    // Serialize form data as query params, if present.
    const baseUrl = UrlService.getUrlFromHref(href, this.url);
    const url = UrlService.addFormDataToUrl(baseUrl, formData);

    let preloadScreen = null;
    if (showIndicatorId) {
      const screens: NodeList<element> = this.document.getElementsByTagNameNS(
        Namespaces.HYPERVIEW,
        'screen',
      );
      const loadingScreen: ?Element = Array.from(screens).find(
        s =&gt; s &amp;&amp; s.getAttribute('id') === showIndicatorId,
      );
      if (loadingScreen) {
        preloadScreen = Date.now(); // Not trully unique but sufficient for our use-case
        this.setPreloadScreen(preloadScreen, loadingScreen);
      }
    }

    const routeParams = { url, preloadScreen, delay };

    switch (action) {
      case NAV_ACTIONS.PUSH:
        this.navigation.push(routeParams);</element>
github Instawork / hyperview / src / components / hv-picker-field / index.js View on Github external
renderPicker = (style: StyleSheetType&lt;*&gt;): ReactNode =&gt; {
    const element: Element = this.props.element;
    const props = {
      onValueChange: value =&gt; {
        this.setState({ pickerValue: value });
      },
      selectedValue: this.state.pickerValue,
      style,
    };

    // Gets all of the  elements. All picker item elements
    // with a value and label are turned into options for the picker.
    const children: Array = Array.from(
      element.getElementsByTagNameNS(
        Namespaces.HYPERVIEW,
        LOCAL_NAME.PICKER_ITEM,
      ),
    )
      .filter(Boolean)
      .map((item: Element) =&gt; {
        const label: ?DOMString = item.getAttribute('label');
        const value: ?DOMString = item.getAttribute('value');
        if (!label || value === null) {
          return null;
        }
        return React.createElement(Picker.Item, { label, value });
      });

    return React.createElement(Picker, props, ...children);
  };
github Instawork / hyperview / src / services / index.js View on Github external
export const getFirstTag = (document: Document, localName: LocalName) => {
  const elements = document.getElementsByTagNameNS(
    Namespaces.HYPERVIEW,
    localName,
  );
  if (elements && elements[0]) {
    return elements[0];
  }
  return null;
};
github Instawork / hyperview / src / components / hv-view / index.js View on Github external
render() {
    const { element, stylesheets, onUpdate, options } = this.props;
    let viewOptions = options;
    const { skipHref } = viewOptions || {};
    const props: InternalProps = createProps(element, stylesheets, viewOptions);
    const scrollable = !!element.getAttribute('scroll');
    let Component = View;
    const inputRefs = [];
    if (scrollable) {
      const textFields = element.getElementsByTagNameNS(
        Namespaces.HYPERVIEW,
        'text-field',
      );
      const textAreas = element.getElementsByTagNameNS(
        Namespaces.HYPERVIEW,
        'text-area',
      );
      const hasFields = textFields.length > 0 || textAreas.length > 0;
      Component = hasFields
        ? KeyboardAwareScrollViewWithScrollContext
        : ScrollViewWithScrollContext;

      props.id = element.getAttribute('id');
      if (hasFields) {
        props.extraScrollHeight = 32;
        props.keyboardOpeningTime = 0;
        props.keyboardShouldPersistTaps = 'handled';
        props.scrollEventThrottle = 16;
        props.getTextInputRefs = () => inputRefs;
        const registerInputHandler = ref => {
          inputRefs.push(ref);
github Instawork / hyperview / src / components / hv-spinner / index.js View on Github external
/**
 * Copyright (c) Garuda Labs, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 */

import * as Namespaces from 'hyperview/src/services/namespaces';
import React, { PureComponent } from 'react';
import { ActivityIndicator } from 'react-native';
import { LOCAL_NAME } from 'hyperview/src/types';
import type { Props } from './types';

export default class HvSpinner extends PureComponent {
  static namespaceURI = Namespaces.HYPERVIEW;
  static localName = LOCAL_NAME.SPINNER;
  props: Props;

  render() {
    const { element } = this.props;
    const color = element.getAttribute('color') || undefined;
    return ;
  }
}
github Instawork / hyperview / src / components / hv-web-view / index.js View on Github external
*
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 */

import * as Namespaces from 'hyperview/src/services/namespaces';
import React, { PureComponent } from 'react';
import { ActivityIndicator } from 'react-native';
import { LOCAL_NAME } from 'hyperview/src/types';
import type { Props } from './types';
import WebView from 'react-native-webview';
import { createProps } from 'hyperview/src/services';

export default class HvWebView extends PureComponent {
  static namespaceURI = Namespaces.HYPERVIEW;
  static localName = LOCAL_NAME.WEB_VIEW;
  props: Props;
  render() {
    const props: any = createProps(
      this.props.element,
      this.props.stylesheets,
      this.props.options,
    );
    const color = props['activity-indicator-color'];
    const injectedJavaScript = props['injected-java-script'];
    const source = { uri: props.url };
    return (
       }
        source={source}
github Instawork / hyperview / src / components / hv-view / index.js View on Github external
import type { InternalProps, Props } from './types';
import React, { PureComponent } from 'react';
import { ScrollView, View } from 'react-native';
import { addHref, createProps } from 'hyperview/src/services';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scrollview';
import { LOCAL_NAME } from 'hyperview/src/types';

const ScrollViewWithScrollContext = ScrollContext.withScrollableComponent(
  ScrollView,
);
const KeyboardAwareScrollViewWithScrollContext = ScrollContext.withScrollableComponent(
  KeyboardAwareScrollView,
);

export default class HvView extends PureComponent {
  static namespaceURI = Namespaces.HYPERVIEW;
  static localName = LOCAL_NAME.VIEW;
  static localNameAliases = [
    LOCAL_NAME.BODY,
    LOCAL_NAME.FORM,
    LOCAL_NAME.HEADER,
    LOCAL_NAME.ITEM,
    LOCAL_NAME.SECTION_TITLE,
  ];
  props: Props;

  render() {
    const { element, stylesheets, onUpdate, options } = this.props;
    let viewOptions = options;
    const { skipHref } = viewOptions || {};
    const props: InternalProps = createProps(element, stylesheets, viewOptions);
    const scrollable = !!element.getAttribute('scroll');
github Instawork / hyperview / src / components / hv-select-multiple / index.js View on Github external
onToggle = (selectedValue: ?DOMString) =&gt; {
    const { element, onUpdate } = this.props;
    const newElement = element.cloneNode(true);
    const options = newElement.getElementsByTagNameNS(
      Namespaces.HYPERVIEW,
      'option',
    );
    for (let i = 0; i &lt; options.length; i += 1) {
      const option = options.item(i);
      if (option) {
        const value = option.getAttribute('value');
        if (value === selectedValue) {
          const selected = option.getAttribute('selected') === 'true';
          option.setAttribute('selected', selected ? 'false' : 'true');
        }
      }
    }
    onUpdate('#', 'swap', element, { newElement });
  };