當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript utils.isFileOrResourcePath函數代碼示例

本文整理匯總了TypeScript中tns-core-modules/utils/utils.isFileOrResourcePath函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isFileOrResourcePath函數的具體用法?TypeScript isFileOrResourcePath怎麽用?TypeScript isFileOrResourcePath使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了isFileOrResourcePath函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getPlaceholderImageDrawable

  public static getPlaceholderImageDrawable(value) {

    let fileName = "",
      drawable = null;


    if (types.isString(value)) {

      value = value.trim();

      if (utils.isFileOrResourcePath(value)) {


        if (0 === value.indexOf("~/")) {
          fileName = fs.path.join(fs.knownFolders.currentApp().path, value.replace("~/", ""));
          drawable = android.graphics.drawable.Drawable.createFromPath(fileName);
        } else if (0 === value.indexOf("res")) {
          fileName = value;
          let res = utils.ad.getApplicationContext().getResources();
          let resName = fileName.substr(utils.RESOURCE_PREFIX.length);
          let identifier = res.getIdentifier(resName, 'drawable', utils.ad.getApplication().getPackageName());
          drawable = res.getDrawable(identifier);
        }


      }
    }

    return drawable;

  }
開發者ID:VideoSpike,項目名稱:nativescript-web-image-cache,代碼行數:31,代碼來源:helpers.ts

示例2: getPlaceholderUIImage

  public static getPlaceholderUIImage(value) {
    if (types.isString(value)) {
      if (utils.isFileOrResourcePath(value)) {
        return imageSource.fromFileOrResource(value).ios;
      }
    }

    return undefined;
  }
開發者ID:VideoSpike,項目名稱:nativescript-web-image-cache,代碼行數:9,代碼來源:helpers.ts

示例3: setSource

  static setSource(image, value) {
    image.nativeView.setImageURI(null, null);

    if (types.isString(value)) {
      value = value.trim();
      if (utils.isFileOrResourcePath(value) || 0 === value.indexOf("http")) {
        image.isLoading = true;
        let fileName = "";
        if (0 === value.indexOf("~/")) {
          fileName = fs.path.join(fs.knownFolders.currentApp().path, value.replace("~/", ""));
          fileName = "file:" + fileName;
        } else if (0 === value.indexOf("res")) {
          fileName = value;
          let res = utils.ad.getApplicationContext().getResources();
          let resName = fileName.substr(utils.RESOURCE_PREFIX.length);
          let identifier = res.getIdentifier(resName, 'drawable', utils.ad.getApplication().getPackageName());
          fileName = "res:/" + identifier;
        } else if (0 === value.indexOf("http")) {
          image.isLoading = true;
          fileName = value;
        }

        image.nativeView.setImageURI(android.net.Uri.parse(fileName), null);

        let controllerListener = new ProxyBaseControllerListener();
        controllerListener.setNSCachedImage(image);


        let controller = com.facebook.drawee.backends.pipeline.Fresco.newDraweeControllerBuilder()
          .setControllerListener(controllerListener)
          .setUri(android.net.Uri.parse(fileName))
          .build();
        image.nativeView.setController(controller);
        image.requestLayout();

      } else {

        throw new Error("Path \"" + "\" is not a valid file or resource.");

      }
    }

  }
開發者ID:VideoSpike,項目名稱:nativescript-web-image-cache,代碼行數:43,代碼來源:helpers.ts

示例4: onSrcPropertySet

  public static onSrcPropertySet(nativeWrapper, value) {


    let image = nativeWrapper,
      placeholder = nativeWrapper.placeholder,
      placeholderImage = this.getPlaceholderUIImage(placeholder);
    if (types.isString(value)) {
      value = value.trim();
      if (0 === value.indexOf("http")) {
        image.isLoading = true;
        image.nativeView.sd_setImageWithURLPlaceholderImageCompleted(value, placeholderImage, function() {
          image.isLoading = false;

        });
      } else if (utils.isFileOrResourcePath(value)) {
        image.isLoading = true;
        let source: any = new imageSource.ImageSource();

        if (0 === value.indexOf(utils.RESOURCE_PREFIX)) {
          let path = value.substr(utils.RESOURCE_PREFIX.length);
          source.fromResource(path).then(function() {
            image.isLoading = false;
            image.nativeView.image = source.ios || source.nativeView;
          });
        } else {
          source.fromFile(value).then(function() {
            image.isLoading = false;
            image.nativeView.image = source.ios || source.nativeView;
          });
        }

      }
      image.requestLayout();
    }

  }
開發者ID:VideoSpike,項目名稱:nativescript-web-image-cache,代碼行數:36,代碼來源:helpers.ts

示例5: isFileOrResourcePath

export function isFileOrResourcePath(path: string): boolean {
    return utils.isFileOrResourcePath(path);
}
開發者ID:peoplewareDo,項目名稱:nativescript-svg,代碼行數:3,代碼來源:svg.common.ts


注:本文中的tns-core-modules/utils/utils.isFileOrResourcePath函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。