How to use @tarojs/taro-h5 - 10 common examples

To help you get started, we’ve selected a few @tarojs/taro-h5 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 NervJS / taro / packages / taro-router / src / router / router.tsx View on Github external
history: Types.History;
  mode: 'multi' | 'hash' | 'browser';
  routes: Types.RouteObj[];
  children?: any[];
  customRoutes: Types.CustomRoutes;
}

interface State {
  location: Types.Location;
  routeStack: Types.RouteObj[];
}

type OriginalRoute = string;
type MappedRoute = string;

class Router extends Taro.Component {
  unlisten: () => void;
  lastLocation: Types.Location;
  currentPages: any[] = [];
  customRoutes: [OriginalRoute, MappedRoute][] = [];

  state = {
    location: this.props.history.location,
    routeStack: [] as Types.RouteObj[]
  };

  mountApis () {
    // 挂载Apis
    Taro.getCurrentPages = () => {
      return this.currentPages
    }
  }
github NervJS / taro / packages / taro-router / src / history / createHistory.ts View on Github external
// 记录最后一个location,浏览器前进后退按钮用
    lastLocation = {...nextState.location}

    stateKey = Number(nextState.location.state!.key)

    serialize()

    history.length = globalHistory.length
    const params = {
      fromLocation,
      toLocation: history.location,
      action: history.action
    }

    Taro._$router = history.location
    Taro.eventCenter.trigger('__taroRouterChange', {...params})
    transitionManager.notifyListeners({...params})
  }
github NervJS / taro / packages / taro-router / src / history / createHistory.ts View on Github external
// 记录最后一个location,浏览器前进后退按钮用
    lastLocation = {...nextState.location}

    stateKey = Number(nextState.location.state!.key)

    serialize()

    history.length = globalHistory.length
    const params = {
      fromLocation,
      toLocation: history.location,
      action: history.action
    }

    Taro._$router = history.location
    Taro.eventCenter.trigger('__taroRouterChange', {...params})
    transitionManager.notifyListeners({...params})
  }
github NervJS / taro / packages / taro-router / src / router / router.tsx View on Github external
mountApis () {
    // 挂载Apis
    Taro.getCurrentPages = () => {
      return this.currentPages
    }
  }
github NervJS / taro / packages / taro-components / src / components / navigator / index.js View on Github external
* @property {String} onSuccess 当target="miniProgram"时有效,跳转小程序成功
 */

/**
 * TODO: 参数还需要进一步细化对齐
 * Navigator组件
 * https://developers.weixin.qq.com/miniprogram/dev/component/navigator.html
 **/

@hoverable({
  hoverClass: 'navigator-hover',
  hoverStopPropergation: false,
  hoverStartTime: 50,
  hoverStayTime: 600
})
class Navigator extends Taro.Component {
  /** @type {NavigatorProps} */
  static defaultProps = {
    target: 'self',
    url: null,
    openType: 'navigate',
    delta: null,
    appId: null,
    path: null,
    extraData: {},
    version: 'release',
    onSuccess: null,
    onFail: null,
    onComplete: null,
    isHover: false
  }
  /** @type {NavigationProps}  */
github NervJS / taro / packages / taro-components / src / components / tabbar / tabbarItem.js View on Github external
import Taro from '@tarojs/taro-h5'
import classNames from 'classnames'
import Nerv from 'nervjs'

const noop = () => {}

export default class Tabbar extends Taro.Component {
  static defaultProps = {
    index: null,
    isSelected: false,
    textColor: {},
    iconPath: '',
    onSelect: noop,
    badgeText: null,
    showRedDot: false
  }

  onClick = () => {
    this.props.onSelect(this.props.index)
  }

  render () {
    const { isSelected, index, textColor, iconPath, text, badgeText, showRedDot } = this.props
github NervJS / taro / packages / taro-mobx-h5 / src / Provider.js View on Github external
import { Children } from 'nervjs'
import Taro from '@tarojs/taro-h5'
import { setStore } from '@tarojs/mobx-common'

export default class Provider extends Taro.Component {
  constructor (props) {
    super(props)
    setStore(props.store)
  }

  render () {
    return Children.only(this.props.children)
  }
}
github NervJS / taro / packages / taro-components / src / utils / hoverable.js View on Github external
return ComponentClass => {
    return class HoverableComponent extends Taro.Component {
      static defaultProps = {
        hoverClass,
        hoverStopPropergation,
        hoverStartTime,
        hoverStayTime
      }
      constructor (props, ctx) {
        super(props, ctx)
        this.state = this.getInitState(this.props)
      }

      touchStartTimer = null
      touchEndTimer = null

      state = {
        isHover: false,
github NervJS / taro / packages / taro-components / src / utils / touchable.js View on Github external
return ComponentClass => {
    return class TouchableComponent extends Taro.Component {
      static defaultProps = {
        onTouchStart: null,
        onTouchMove: null,
        onTouchEnd: null,
        onTouchCancel: null,
        onLongTap: null
      }
      timer = null
      offset = {
        offsetX: 0,
        offsetY: 0
      }

      onTouchStart = e => {
        const { onTouchStart, onLongTap } = this.props
        Object.defineProperty(e, 'touches', { value: transformTouches(e.touches, this.offset) })
github NervJS / taro / packages / taro-router / src / router / route.tsx View on Github external
if (panel) {
    res = {
      set: pos => { panel.scrollTop = pos },
      get: () => panel.scrollTop
    }
  } else {
    res = {
      set: pos => window.scrollTo(0, pos),
      get: () => window.pageYOffset
    }
  }
  return res
}
let scroller

class Route extends Taro.Component {
  matched = false;
  wrappedComponent;
  componentRef;
  containerRef;
  isRoute = true;
  scrollPos = 0;

  constructor (props, context) {
    super(props, context)
    this.matched = this.computeMatch(this.props.currentLocation)
  }

  computeMatch (currentLocation) {
    const path = currentLocation.path;
    const key = currentLocation.state.key;
    const isIndex = this.props.isIndex;