java类com.facebook.react.bridge.Callback的实例源码

AsyncStorageModule.java 文件源码 项目:RNLearn_Project1 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Clears the database.
 */
@ReactMethod
public void clear(final Callback callback) {
  new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
    @Override
    protected void doInBackgroundGuarded(Void... params) {
      if (!mReactDatabaseSupplier.ensureDatabase()) {
        callback.invoke(AsyncStorageErrorUtil.getDBError(null));
        return;
      }
      try {
        mReactDatabaseSupplier.clear();
        callback.invoke();
      } catch (Exception e) {
        FLog.w(ReactConstants.TAG, e.getMessage(), e);
        callback.invoke(AsyncStorageErrorUtil.getError(null, e.getMessage()));
      }
    }
  }.execute();
}
UdeskModule.java 文件源码 项目:react-native-udesk 阅读 32 收藏 0 点赞 0 评论 0
@ReactMethod
public void createCommodity (final ReadableMap options, final Callback callback) { // 都是必传的(productDetail 可选)
    cleanResponse();
    if (!hasAndNotEmpty(options, "productTitle")) {
        invokeError(callback, "title is empty");
        return;
    }
    if (!hasAndNotEmpty(options, "productImageUrl")) {
        invokeError(callback, "imageUrl is empty");
        return;
    }
    if (!hasAndNotEmpty(options, "productURL")) {
        invokeError(callback, "productUrl is empty");
        return;
    }
    UdeskCommodityItem item = new UdeskCommodityItem();
    item.setTitle(options.getString("productTitle"));// 商品主标题
    if (hasAndNotEmpty(options, "productDetail")) {
        item.setSubTitle(options.getString("productDetail"));//商品副标题
    }
    item.setThumbHttpUrl(options.getString("productImageUrl"));// 左侧图片
    item.setCommodityUrl(options.getString("productURL"));// 商品网络链接
    UdeskSDKManager.getInstance().setCommodity(item);
    UdeskSDKManager.getInstance().toLanuchChatAcitvity(mReactContext.getApplicationContext());
}
FlatUIViewOperationQueue.java 文件源码 项目:RNLearn_Project1 阅读 41 收藏 0 点赞 0 评论 0
private MeasureVirtualView(
    int reactTag,
    float scaledX,
    float scaledY,
    float scaledWidth,
    float scaledHeight,
    boolean relativeToWindow,
    Callback callback) {
  mReactTag = reactTag;
  mScaledX = scaledX;
  mScaledY = scaledY;
  mScaledWidth = scaledWidth;
  mScaledHeight = scaledHeight;
  mCallback = callback;
  mRelativeToWindow = relativeToWindow;
}
UIImplementation.java 文件源码 项目:RNLearn_Project1 阅读 38 收藏 0 点赞 0 评论 0
/**
 * Measures the view specified by tag relative to the given ancestorTag. This means that the
 * returned x, y are relative to the origin x, y of the ancestor view. Results are stored in the
 * given outputBuffer. We allow ancestor view and measured view to be the same, in which case
 * the position always will be (0, 0) and method will only measure the view dimensions.
 */
public void measureLayout(
    int tag,
    int ancestorTag,
    Callback errorCallback,
    Callback successCallback) {
  try {
    measureLayout(tag, ancestorTag, mMeasureBuffer);
    float relativeX = PixelUtil.toDIPFromPixel(mMeasureBuffer[0]);
    float relativeY = PixelUtil.toDIPFromPixel(mMeasureBuffer[1]);
    float width = PixelUtil.toDIPFromPixel(mMeasureBuffer[2]);
    float height = PixelUtil.toDIPFromPixel(mMeasureBuffer[3]);
    successCallback.invoke(relativeX, relativeY, width, height);
  } catch (IllegalViewOperationException e) {
    errorCallback.invoke(e.getMessage());
  }
}
ReactNativeDownloadManagerModule.java 文件源码 项目:react-native-simple-download-manager 阅读 35 收藏 0 点赞 0 评论 0
@ReactMethod
public void attachOnCompleteListener(String downloadId, Callback onComplete) {
    try {
        long dloadId = Long.parseLong(downloadId);
        appDownloads.put(dloadId, onComplete);
        WritableMap status = downloader.checkDownloadStatus(Long.parseLong(downloadId));
        ArrayList<String> alreadyDoneStatuses = new ArrayList<>(Arrays.asList("STATUS_SUCCESSFUL", "STATUS_FAILED"));
        String currentStatus = status.getString("status");
        if (alreadyDoneStatuses.contains(currentStatus)) {
            appDownloads.remove(dloadId);
            onComplete.invoke(null, status);
        }
    } catch (Exception e) {
        onComplete.invoke(e.getMessage(), null);
    }
}
FlatUIViewOperationQueue.java 文件源码 项目:RNLearn_Project1 阅读 52 收藏 0 点赞 0 评论 0
public void enqueueMeasureVirtualView(
    int reactTag,
    float scaledX,
    float scaledY,
    float scaledWidth,
    float scaledHeight,
    boolean relativeToWindow,
    Callback callback) {
  enqueueUIOperation(new MeasureVirtualView(
      reactTag,
      scaledX,
      scaledY,
      scaledWidth,
      scaledHeight,
      relativeToWindow,
      callback));
}
NativeAnimatedModule.java 文件源码 项目:RNLearn_Project1 阅读 37 收藏 0 点赞 0 评论 0
@ReactMethod
public void startAnimatingNode(
    final int animationId,
    final int animatedNodeTag,
    final ReadableMap animationConfig,
    final Callback endCallback) {
  mOperations.add(new UIThreadOperation() {
    @Override
    public void execute(NativeAnimatedNodesManager animatedNodesManager) {
      animatedNodesManager.startAnimatingNode(
        animationId,
        animatedNodeTag,
        animationConfig,
        endCallback);
    }
  });
}
ForwardingCookieHandler.java 文件源码 项目:RNLearn_Project1 阅读 32 收藏 0 点赞 0 评论 0
public void clearCookies(final Callback callback) {
  if (USES_LEGACY_STORE) {
    new GuardedResultAsyncTask<Boolean>(mContext) {
      @Override
      protected Boolean doInBackgroundGuarded() {
        getCookieManager().removeAllCookie();
        mCookieSaver.onCookiesModified();
        return true;
      }

      @Override
      protected void onPostExecuteGuarded(Boolean result) {
        callback.invoke(result);
      }
    }.execute();
  } else {
    clearCookiesAsync(callback);
  }
}
PybWifiParamModule.java 文件源码 项目:react-native-pybwifiparam 阅读 31 收藏 0 点赞 0 评论 0
@ReactMethod
public void getWifiSSID(Callback callback){
    String SSID;
    Context context = this.getReactApplicationContext();
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if(networkInfo != null && networkInfo.isConnected()){
        WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        SSID = wifiInfo.getSSID();
        if(SSID.startsWith("\"") && SSID.endsWith("\""))
            SSID = SSID.substring(1, SSID.length()-1);
        callback.invoke(null, SSID);
    }
    else{
        callback.invoke("Error: unable to retrieve SSID.", null);
    }
}
ImageEditingManager.java 文件源码 项目:RNLearn_Project1 阅读 32 收藏 0 点赞 0 评论 0
private CropTask(
    ReactContext context,
    String uri,
    int x,
    int y,
    int width,
    int height,
    Callback success,
    Callback error) {
  super(context);
  if (x < 0 || y < 0 || width <= 0 || height <= 0) {
    throw new JSApplicationIllegalArgumentException(String.format(
        "Invalid crop rectangle: [%d, %d, %d, %d]", x, y, width, height));
  }
  mContext = context;
  mUri = uri;
  mX = x;
  mY = y;
  mWidth = width;
  mHeight = height;
  mSuccess = success;
  mError = error;
}
ImageEditingManager.java 文件源码 项目:RNLearn_Project1 阅读 30 收藏 0 点赞 0 评论 0
private CropTask(
    ReactContext context,
    String uri,
    int x,
    int y,
    int width,
    int height,
    Callback success,
    Callback error) {
  super(context);
  if (x < 0 || y < 0 || width <= 0 || height <= 0) {
    throw new JSApplicationIllegalArgumentException(String.format(
        "Invalid crop rectangle: [%d, %d, %d, %d]", x, y, width, height));
  }
  mContext = context;
  mUri = uri;
  mX = x;
  mY = y;
  mWidth = width;
  mHeight = height;
  mSuccess = success;
  mError = error;
}
ForwardingCookieHandler.java 文件源码 项目:RNLearn_Project1 阅读 55 收藏 0 点赞 0 评论 0
public void clearCookies(final Callback callback) {
  if (USES_LEGACY_STORE) {
    new GuardedResultAsyncTask<Boolean>(mContext) {
      @Override
      protected Boolean doInBackgroundGuarded() {
        getCookieManager().removeAllCookie();
        mCookieSaver.onCookiesModified();
        return true;
      }

      @Override
      protected void onPostExecuteGuarded(Boolean result) {
        callback.invoke(result);
      }
    }.execute();
  } else {
    clearCookiesAsync(callback);
  }
}
UIImplementation.java 文件源码 项目:RNLearn_Project1 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Measures the view specified by tag relative to the given ancestorTag. This means that the
 * returned x, y are relative to the origin x, y of the ancestor view. Results are stored in the
 * given outputBuffer. We allow ancestor view and measured view to be the same, in which case
 * the position always will be (0, 0) and method will only measure the view dimensions.
 */
public void measureLayout(
    int tag,
    int ancestorTag,
    Callback errorCallback,
    Callback successCallback) {
  try {
    measureLayout(tag, ancestorTag, mMeasureBuffer);
    float relativeX = PixelUtil.toDIPFromPixel(mMeasureBuffer[0]);
    float relativeY = PixelUtil.toDIPFromPixel(mMeasureBuffer[1]);
    float width = PixelUtil.toDIPFromPixel(mMeasureBuffer[2]);
    float height = PixelUtil.toDIPFromPixel(mMeasureBuffer[3]);
    successCallback.invoke(relativeX, relativeY, width, height);
  } catch (IllegalViewOperationException e) {
    errorCallback.invoke(e.getMessage());
  }
}
NativeViewHierarchyManager.java 文件源码 项目:RNLearn_Project1 阅读 32 收藏 0 点赞 0 评论 0
/**
 * Show a {@link PopupMenu}.
 *
 * @param reactTag the tag of the anchor view (the PopupMenu is displayed next to this view); this
 *        needs to be the tag of a native view (shadow views can not be anchors)
 * @param items the menu items as an array of strings
 * @param success will be called with the position of the selected item as the first argument, or
 *        no arguments if the menu is dismissed
 */
public void showPopupMenu(int reactTag, ReadableArray items, Callback success) {
  UiThreadUtil.assertOnUiThread();
  View anchor = mTagsToViews.get(reactTag);
  if (anchor == null) {
    throw new JSApplicationIllegalArgumentException("Could not find view with tag " + reactTag);
  }
  PopupMenu popupMenu = new PopupMenu(getReactContextForView(reactTag), anchor);

  Menu menu = popupMenu.getMenu();
  for (int i = 0; i < items.size(); i++) {
    menu.add(Menu.NONE, Menu.NONE, i, items.getString(i));
  }

  PopupMenuCallbackHandler handler = new PopupMenuCallbackHandler(success);
  popupMenu.setOnMenuItemClickListener(handler);
  popupMenu.setOnDismissListener(handler);

  popupMenu.show();
}
WebRTCModule.java 文件源码 项目:react-native-webrtc 阅读 41 收藏 0 点赞 0 评论 0
private synchronized void processPicture(byte[] jpeg, int captureTarget, double maxJpegQuality,
                                         int maxSize, int orientation, List<String> paths,
                                         Callback successCallback, Callback errorCallback,
                                         String streamId, int totalPictures) {

    Log.d(TAG, "Processing picture");
    try {
        String path = savePicture(jpeg, captureTarget, maxJpegQuality, maxSize, orientation);

        Log.d(TAG, "Saved picture to " + path);

        paths.add(path);

        if (paths.size() == totalPictures) {
            WritableArray pathsArray = Arguments.createArray();
            for (String p : paths) {
                pathsArray.pushString(p);
            }
            successCallback.invoke(pathsArray);
            imagePorcessingHandler.removeCallbacksAndMessages(null);
        }
    } catch (IOException e) {
        String message = "Could not save picture for stream id " + streamId;
        Log.d(TAG, message, e);
        errorCallback.invoke(message);
        imagePorcessingHandler.removeCallbacksAndMessages(null);
    }
}
UIViewOperationQueue.java 文件源码 项目:RNLearn_Project1 阅读 29 收藏 0 点赞 0 评论 0
private FindTargetForTouchOperation(
    final int reactTag,
    final float targetX,
    final float targetY,
    final Callback callback) {
  super();
  mReactTag = reactTag;
  mTargetX = targetX;
  mTargetY = targetY;
  mCallback = callback;
}
BiometricModule.java 文件源码 项目:FingerPrint-Authentication-With-React-Native-Android 阅读 25 收藏 0 点赞 0 评论 0
@ReactMethod
public void retrieveUserSettings(String key, Callback successCallbackUserSettings) {

    if (key.equalsIgnoreCase(AppConstants.LOCK_FINGERPRINT)) {
        successCallbackUserSettings.invoke(PreferenceHelper.getPrefernceHelperInstace().getBoolean(AppContext,
                key, true));
    } else {
        successCallbackUserSettings.invoke(PreferenceHelper.getPrefernceHelperInstace().getBoolean(AppContext,
                key, false));
    }

}
AsyncStorageModuleTest.java 文件源码 项目:RNLearn_Project1 阅读 35 收藏 0 点赞 0 评论 0
@Test
public void testMultiRemove() {
  final String key1 = "foo1";
  final String key2 = "foo2";
  final String value1 = "bar1";
  final String value2 = "bar2";

  JavaOnlyArray keyValues = new JavaOnlyArray();
  keyValues.pushArray(getArray(key1, value1));
  keyValues.pushArray(getArray(key2, value2));
  mStorage.multiSet(keyValues, mock(Callback.class));

  JavaOnlyArray keys = new JavaOnlyArray();
  keys.pushString(key1);
  keys.pushString(key2);

  Callback getCallback = mock(Callback.class);
  mStorage.multiRemove(keys, getCallback);
  Mockito.verify(getCallback, Mockito.times(1)).invoke();

  Callback getAllCallback = mock(Callback.class);
  mStorage.getAllKeys(getAllCallback);
  Mockito.verify(getAllCallback, Mockito.times(1)).invoke(null, mEmptyArray);

  mStorage.multiSet(keyValues, mock(Callback.class));

  keys.pushString("fakeKey");
  Callback getCallback2 = mock(Callback.class);
  mStorage.multiRemove(keys, getCallback2);
  Mockito.verify(getCallback2, Mockito.times(1)).invoke();

  Callback getAllCallback2 = mock(Callback.class);
  mStorage.getAllKeys(getAllCallback2);
  Mockito.verify(getAllCallback2, Mockito.times(1)).invoke(null, mEmptyArray);
}
UIViewOperationQueue.java 文件源码 项目:RNLearn_Project1 阅读 25 收藏 0 点赞 0 评论 0
public void enqueueShowPopupMenu(
    int reactTag,
    ReadableArray items,
    Callback error,
    Callback success) {
  mOperations.add(new ShowPopupMenuOperation(reactTag, items, success));
}
TaplyticsReactModule.java 文件源码 项目:taplytics-react-native 阅读 34 收藏 0 点赞 0 评论 0
@ReactMethod
public void setTaplyticsPushTokenListener(final Callback callback) {
    Taplytics.setTaplyticsPushTokenListener(new TaplyticsPushTokenListener() {
        @Override
        public void pushTokenReceived(String s) {
            callback.invoke(s);
        }
    });
}
TaplyticsReactModule.java 文件源码 项目:taplytics-react-native 阅读 34 收藏 0 点赞 0 评论 0
@ReactMethod
public void propertiesLoadedCallback(final Callback callback) {
    Taplytics.getRunningExperimentsAndVariations(new TaplyticsRunningExperimentsListener() {
        @Override
        public void runningExperimentsAndVariation(Map<String, String> map) {
            callback.invoke();
        }
    });
}
AsyncStorageModule.java 文件源码 项目:RNLearn_Project1 阅读 42 收藏 0 点赞 0 评论 0
/**
 * Returns an array with all keys from the database.
 */
@ReactMethod
public void getAllKeys(final Callback callback) {
  new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
    @Override
    protected void doInBackgroundGuarded(Void... params) {
      if (!ensureDatabase()) {
        callback.invoke(AsyncStorageErrorUtil.getDBError(null), null);
        return;
      }
      WritableArray data = Arguments.createArray();
      String[] columns = {KEY_COLUMN};
      Cursor cursor = mReactDatabaseSupplier.get()
          .query(TABLE_CATALYST, columns, null, null, null, null, null);
      try {
        if (cursor.moveToFirst()) {
          do {
            data.pushString(cursor.getString(0));
          } while (cursor.moveToNext());
        }
      } catch (Exception e) {
        FLog.w(ReactConstants.TAG, e.getMessage(), e);
        callback.invoke(AsyncStorageErrorUtil.getError(null, e.getMessage()), null);
        return;
      } finally {
        cursor.close();
      }
      callback.invoke(null, data);
    }
  }.execute();
}
ReactActivityDelegate.java 文件源码 项目:RNLearn_Project1 阅读 31 收藏 0 点赞 0 评论 0
public void onRequestPermissionsResult(
  final int requestCode,
  final String[] permissions,
  final int[] grantResults) {
  mPermissionsCallback = new Callback() {
    @Override
    public void invoke(Object... args) {
      if (mPermissionListener != null && mPermissionListener.onRequestPermissionsResult(requestCode, permissions, grantResults)) {
        mPermissionListener = null;
      }
    }
  };
}
GoogleFitModule.java 文件源码 项目:react-native-google-fit 阅读 36 收藏 0 点赞 0 评论 0
@ReactMethod
public void getDailyCalorieSamples(double startDate,
                                   double endDate,
                                   Callback errorCallback,
                                   Callback successCallback) {

    try {
        successCallback.invoke(mGoogleFitManager.getCalorieHistory().aggregateDataByDate((long)startDate, (long)endDate));
    } catch (IllegalViewOperationException e) {
        errorCallback.invoke(e.getMessage());
    }
}
GoogleFitModule.java 文件源码 项目:react-native-google-fit 阅读 29 收藏 0 点赞 0 评论 0
@ReactMethod
public void saveWeight(ReadableMap weightSample,
                       Callback errorCallback,
                       Callback successCallback) {

    try {
        successCallback.invoke(mGoogleFitManager.getWeightsHistory().saveWeight(weightSample));
    } catch (IllegalViewOperationException e) {
        errorCallback.invoke(e.getMessage());
    }
}
UIManagerModuleTest.java 文件源码 项目:RNLearn_Project1 阅读 26 收藏 0 点赞 0 评论 0
@Test
public void testAddAndRemoveAnimation() {
  UIManagerModule uiManagerModule = getUIManagerModule();
  TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManagerModule);

  AnimationPropertyUpdater mockPropertyUpdater = mock(AnimationPropertyUpdater.class);
  Animation mockAnimation = spy(new AnimationStub(1000, mockPropertyUpdater));
  Callback callbackMock = mock(Callback.class);

  int rootTag = hierarchy.rootView;
  uiManagerModule.createView(
      hierarchy.rootView,
      ReactViewManager.REACT_CLASS,
      rootTag,
      JavaOnlyMap.of("collapsable", false));

  uiManagerModule.registerAnimation(mockAnimation);
  uiManagerModule.addAnimation(hierarchy.rootView, 1000, callbackMock);
  uiManagerModule.removeAnimation(hierarchy.rootView, 1000);

  uiManagerModule.onBatchComplete();
  executePendingFrameCallbacks();

  verify(callbackMock, times(1)).invoke(false);
  verify(mockAnimation).run();
  verify(mockAnimation).cancel();
}
GoogleFitModule.java 文件源码 项目:react-native-google-fit 阅读 36 收藏 0 点赞 0 评论 0
@ReactMethod
public void isAvailable(Callback errorCallback, Callback successCallback) { // true if GoogleFit installed
    try {
        successCallback.invoke(isAvailableCheck());
    } catch (IllegalViewOperationException e) {
        errorCallback.invoke(e.getMessage());
    }
}
GoogleFitModule.java 文件源码 项目:react-native-google-fit 阅读 36 收藏 0 点赞 0 评论 0
@ReactMethod
public void isEnabled(Callback errorCallback, Callback successCallback) { // true if permission granted
    try {
        successCallback.invoke(isEnabledCheck());
    } catch (IllegalViewOperationException e) {
        errorCallback.invoke(e.getMessage());
    }
}
ImageEditingManager.java 文件源码 项目:RNLearn_Project1 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Crop an image. If all goes well, the success callback will be called with the file:// URI of
 * the new image as the only argument. This is a temporary file - consider using
 * CameraRollManager.saveImageWithTag to save it in the gallery.
 *
 * @param uri the MediaStore URI of the image to crop
 * @param options crop parameters specified as {@code {offset: {x, y}, size: {width, height}}}.
 *        Optionally this also contains  {@code {targetSize: {width, height}}}. If this is
 *        specified, the cropped image will be resized to that size.
 *        All units are in pixels (not DPs).
 * @param success callback to be invoked when the image has been cropped; the only argument that
 *        is passed to this callback is the file:// URI of the new image
 * @param error callback to be invoked when an error occurs (e.g. can't create file etc.)
 */
@ReactMethod
public void cropImage(
    String uri,
    ReadableMap options,
    final Callback success,
    final Callback error) {
  ReadableMap offset = options.hasKey("offset") ? options.getMap("offset") : null;
  ReadableMap size = options.hasKey("size") ? options.getMap("size") : null;
  if (offset == null || size == null ||
      !offset.hasKey("x") || !offset.hasKey("y") ||
      !size.hasKey("width") || !size.hasKey("height")) {
    throw new JSApplicationIllegalArgumentException("Please specify offset and size");
  }
  if (uri == null || uri.isEmpty()) {
    throw new JSApplicationIllegalArgumentException("Please specify a URI");
  }

  CropTask cropTask = new CropTask(
      getReactApplicationContext(),
      uri,
      (int) offset.getDouble("x"),
      (int) offset.getDouble("y"),
      (int) size.getDouble("width"),
      (int) size.getDouble("height"),
      success,
      error);
  if (options.hasKey("displaySize")) {
    ReadableMap targetSize = options.getMap("displaySize");
    cropTask.setTargetSize(targetSize.getInt("width"), targetSize.getInt("height"));
  }
  cropTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
ActivityStarterModule.java 文件源码 项目:react-native-android-activity 阅读 34 收藏 0 点赞 0 评论 0
@ReactMethod
void getActivityName(@Nonnull Callback callback) {
    Activity activity = getCurrentActivity();
    if (activity != null) {
        callback.invoke(activity.getClass().getSimpleName());
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号