UNPKG

house-middleware-sdk

Version:

58 hosue rn native sdk

151 lines (137 loc) 3.96 kB
/* * @method showLoading 展示loading */ import React from 'react'; import { NativeModules, Platform } from 'react-native'; import checker from '../utils/checker' function wbloading(param) { //loading参数校验 const error = checker(arguments, [ { "cmd": 's', "type": "s" }, ], 'loadingBar' ); // 线上环境报错不调起 Native 的 API if (error === 'error') { return error } if (NativeModules.HSFLoadingBar && NativeModules.HSFLoadingBar.execute) { NativeModules.HSFLoadingBar.execute(param); } else { require('@w/wbapp') .loading(param); } } export function initLoading(param) { require('../utils/findImpl') .default( () => showLoadingWbImpl(param), () => { }, () => { }, () => showLoadingWbImpl(param) ); } export function showLoading(param) { require('../utils/findImpl') .default( () => showLoadingWbImpl(param), () => showLoadingAjkImpl(param), () => showLoadingYdjjrImpl(param), () => showLoadingWbtzImpl(param) ); } function showLoadingWbImpl(param) { if (param && (typeof param !== "object")) { console.warn('this type of param must is a object or undefined'); return; } let orgParam = { cmd: 'show', type: 'nonblock', }; wbloading(Object.assign(orgParam, param)); } function showLoadingAjkImpl(param) { require('ajkapp') .showLoading(); } function showLoadingYdjjrImpl(param) { NativeModules.BrokerLoading.showLoading(); } //TODO:{58同镇 显示loading...} function showLoadingWbtzImpl(param) { if (param && (typeof param !== "object")) { console.warn('this type of param must is a object or undefined'); return; } if (param) { // loading参数校验 const error = checker(arguments, [{ cmd: 's', type: 's' }], 'loadingBar') // 线上环境报错不调起 Native 的 API if (error === 'error') { return error } } let orgParam = { cmd: 'show', // show || hide type: 'nonblock', // nonblock }; NativeModules?.WBLoadingBar?.execute(param || orgParam) } /* * @method hideLoading 隐藏loading */ export function hideLoading(param) { require('../utils/findImpl') .default( () => hideLoadingWbImpl(param), () => hideLoadingAjkImpl(param), () => hideLoadingYdjjrImpl(), () => hideLoadingWbtzImpl(param) ); } function hideLoadingWbImpl(param) { let defaultParam = { cmd: 'hide', type: 'nonblock' }; if (NativeModules.HSFLoadingBar && NativeModules.HSFLoadingBar.execute) { NativeModules.HSFLoadingBar.execute(defaultParam); } else { if (param && (typeof param !== "object")) { console.warn('this type of param must is a object or undefined'); return; } require('@w/wbapp') .loading(Object.assign(defaultParam, param)); } } function hideLoadingAjkImpl(param) { require('ajkapp') .hideLoading(); } function hideLoadingYdjjrImpl() { NativeModules.BrokerLoading.hideLoading(); } //TODO:{58同镇 隐藏loading...} function hideLoadingWbtzImpl(param) { if (param && (typeof param !== "object")) { console.warn('this type of param must is a object or undefined'); return; } if (param) { // loading参数校验 const error = checker(arguments, [{ cmd: 's', type: 's' }], 'loadingBar') // 线上环境报错不调起 Native 的 API if (error === 'error') { return error } } let orgParam = { cmd: 'hide', // show || hide type: 'nonblock', // nonblock }; NativeModules?.WBLoadingBar?.execute(param || orgParam) }