Java Code Examples for com.facebook.react.bridge.ReadableMap#hasKey()

The following examples show how to use com.facebook.react.bridge.ReadableMap#hasKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlobModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public RequestBody toRequestBody(ReadableMap data, String contentType) {
  String type = contentType;
  if (data.hasKey("type") && !data.getString("type").isEmpty()) {
    type = data.getString("type");
  }
  if (type == null) {
    type = "application/octet-stream";
  }
  ReadableMap blob = data.getMap("blob");
  String blobId = blob.getString("blobId");
  byte[] bytes = resolve(
    blobId,
    blob.getInt("offset"),
    blob.getInt("size"));

  return RequestBody.create(MediaType.parse(type), bytes);
}
 
Example 2
Source File: DatePickerDialogModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
private Bundle createFragmentArguments(ReadableMap options) {
  final Bundle args = new Bundle();
  if (options.hasKey(ARG_DATE) && !options.isNull(ARG_DATE)) {
    args.putLong(ARG_DATE, (long) options.getDouble(ARG_DATE));
  }
  if (options.hasKey(ARG_MINDATE) && !options.isNull(ARG_MINDATE)) {
    args.putLong(ARG_MINDATE, (long) options.getDouble(ARG_MINDATE));
  }
  if (options.hasKey(ARG_MAXDATE) && !options.isNull(ARG_MAXDATE)) {
    args.putLong(ARG_MAXDATE, (long) options.getDouble(ARG_MAXDATE));
  }
  if (options.hasKey(ARG_MODE) && !options.isNull(ARG_MODE)) {
    args.putString(ARG_MODE, options.getString(ARG_MODE));
  }
  return args;
}
 
Example 3
Source File: FrameBasedAnimationDriver.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public void resetConfig(ReadableMap config) {
  ReadableArray frames = config.getArray("frames");
  int numberOfFrames = frames.size();
  if (mFrames == null || mFrames.length != numberOfFrames) {
    mFrames = new double[numberOfFrames];
  }
  for (int i = 0; i < numberOfFrames; i++) {
    mFrames[i] = frames.getDouble(i);
  }
  mToValue = config.hasKey("toValue") ? config.getDouble("toValue") : 0;
  mIterations = config.hasKey("iterations") ? config.getInt("iterations") : 1;
  mCurrentLoop = 1;
  mHasFinished = mIterations == 0;
  mStartFrameTimeNanos = -1;
}
 
Example 4
Source File: RNAGSGraphicsOverlay.java    From react-native-arcgis-mapview with MIT License 6 votes vote down vote up
public RNAGSGraphicsOverlay(ReadableMap rawData, GraphicsOverlay graphicsOverlay) {
    this.referenceId = rawData.getString("referenceId");
    ReadableArray pointImageDictionaryRaw = rawData.getArray("pointGraphics");
    pointImageDictionary = new HashMap<>();
    this.graphicsOverlay = graphicsOverlay;

    for (int i = 0; i < pointImageDictionaryRaw.size(); i++) {
        ReadableMap item = pointImageDictionaryRaw.getMap(i);
        if (item.hasKey("graphicId")) {
            String graphicId = item.getString("graphicId");
            String uri = item.getMap("graphic").getString("uri");
            pointImageDictionary.put(graphicId, uri);
        }
    }
    // Create graphics within overlay
    ReadableArray rawPoints = rawData.getArray("points");
    for (int i = 0; i < rawPoints.size(); i++) {
        addGraphicsLoop(rawPoints.getMap(i));

    }
}
 
Example 5
Source File: SocketClient.java    From react-native-sockets with MIT License 6 votes vote down vote up
SocketClient(ReadableMap params, ReactContext reactContext) {
    //String addr, int port, boolean autoReconnect
    mReactContext = reactContext;
    dstAddress = params.getString("address");
    dstPort = params.getInt("port");
    if (params.hasKey("timeout")) {
        timeout = params.getInt("timeout");
    } else {
        timeout = 60000;
    }
    if (params.hasKey("reconnect")) {
        reconnectOnClose = params.getBoolean("reconnect");
    }
    if (params.hasKey("maxReconnectAttempts")) {
        maxReconnectAttempts = params.getInt("maxReconnectAttempts");
    }
    if (params.hasKey("reconnectDelay")) {
        reconnectDelay = params.getInt("reconnectDelay");
    }

    Thread socketClientThread = new Thread(new SocketClientThread());
    socketClientThread.start();
}
 
Example 6
Source File: RNZendeskChatModule.java    From react-native-zendesk-chat with MIT License 6 votes vote down vote up
@ReactMethod
public void setVisitorInfo(ReadableMap options) {
    VisitorInfo.Builder builder = new VisitorInfo.Builder();

    if (options.hasKey("name")) {
        builder.name(options.getString("name"));
    }
    if (options.hasKey("email")) {
        builder.email(options.getString("email"));
    }
    if (options.hasKey("phone")) {
        builder.phoneNumber(options.getString("phone"));
    }

    VisitorInfo visitorData = builder.build();

    ZopimChat.setVisitorInfo(visitorData);
}
 
Example 7
Source File: ReactTextInputManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactProp(name = "selection")
public void setSelection(ReactEditText view, @Nullable ReadableMap selection) {
  if (selection == null) {
    return;
  }

  if (selection.hasKey("start") && selection.hasKey("end")) {
    view.setSelection(selection.getInt("start"), selection.getInt("end"));
  }
}
 
Example 8
Source File: ReadableMapUtils.java    From react-native-google-cast with MIT License 5 votes vote down vote up
public static @Nullable Boolean getBoolean(@NonNull ReadableMap map, @NonNull String key) {
    if (!map.hasKey(key)) {
        return null;
    }

    return map.getBoolean(key);
}
 
Example 9
Source File: ReactToolbar.java    From react-native-GPay with MIT License 5 votes vote down vote up
private IconImageInfo getIconImageInfo(ReadableMap source) {
  if (source.hasKey(PROP_ICON_WIDTH) && source.hasKey(PROP_ICON_HEIGHT)) {
    final int width = Math.round(PixelUtil.toPixelFromDIP(source.getInt(PROP_ICON_WIDTH)));
    final int height = Math.round(PixelUtil.toPixelFromDIP(source.getInt(PROP_ICON_HEIGHT)));
    return new IconImageInfo(width, height);
  } else {
    return null;
  }
}
 
Example 10
Source File: SipMessageDTO.java    From react-native-pjsip with GNU General Public License v3.0 5 votes vote down vote up
public static SipMessageDTO fromReadableMap(ReadableMap data) {
    SipMessageDTO result = new SipMessageDTO();

    if (data.hasKey("targetURI")) {
        result.setTargetUri(data.getString("targetURI"));
    }
    if (data.hasKey("headers")) {
        ReadableMap headersData = data.getMap("headers");
        ReadableMapKeySetIterator headersIt = headersData.keySetIterator();
        Map<String, String> headers = new HashMap<>();

        while (headersIt.hasNextKey()) {
            String key = headersIt.nextKey();
            headers.put(key, headersData.getString(key));
        }

        result.setHeaders(headers);
    }
    if (data.hasKey("contentType")) {
        result.setContentType(data.getString("contentType"));
    }
    if (data.hasKey("body")) {
        result.setBody(data.getString("body"));
    }

    return result;
}
 
Example 11
Source File: ReactToolbar.java    From native-navigation with MIT License 5 votes vote down vote up
private IconImageInfo getIconImageInfo(ReadableMap source) {
  if (source.hasKey(PROP_ICON_WIDTH) && source.hasKey(PROP_ICON_HEIGHT)) {
    final int width = Math.round(PixelUtil.toPixelFromDIP(source.getInt(PROP_ICON_WIDTH)));
    final int height = Math.round(PixelUtil.toPixelFromDIP(source.getInt(PROP_ICON_HEIGHT)));
    return new IconImageInfo(width, height);
  } else {
    return null;
  }
}
 
Example 12
Source File: RCTTwilioChatClient.java    From react-native-twilio-chat with MIT License 5 votes vote down vote up
@ReactMethod
public void createClient(String token, ReadableMap props, final Promise promise) {
    final RCTTwilioChatClient tmp = RCTTwilioChatClient.getInstance();
    ChatClient.Properties.Builder builder = new ChatClient.Properties.Builder();

    if (props != null) {
        if (props.hasKey("initialMessageCount")) {
            builder.setInitialMessageCount(props.getInt("initialMessageCount"));
        }
        if (props.hasKey("synchronizationStrategy")) {
            builder.setSynchronizationStrategy(ChatClient.SynchronizationStrategy.valueOf(props.getString("synchronizationStrategy")));
        }
    }

    ChatClient.create(reactContext, token, builder.createProperties(), new CallbackListener<ChatClient>() {
        @Override
        public void onError(ErrorInfo errorInfo) {
            super.onError(errorInfo);
            promise.reject("create-client-error", "Error occurred while attempting to create the client. Error Message: " + errorInfo.getErrorText());
        }

        @Override
        public void onSuccess(ChatClient twilioChatClient) {
            tmp.client = twilioChatClient;
            tmp.client.setListener(tmp);
            promise.resolve(RCTConvert.ChatClient(tmp.client));
        }
    });
}
 
Example 13
Source File: RNKakaoLinkModule.java    From react-native-kakao-links with MIT License 5 votes vote down vote up
private LinkObject createLinkObject(ReadableMap link) {
  LinkObject.Builder linkObject = LinkObject.newBuilder();
  if (link.hasKey("webURL")) linkObject.setWebUrl(link.getString("webURL"));
  if (link.hasKey("mobileWebURL")) linkObject.setMobileWebUrl(link.getString("mobileWebURL"));
  if (link.hasKey("androidExecutionParams"))
    linkObject.setAndroidExecutionParams(link.getString("androidExecutionParams"));
  if (link.hasKey("iosExecutionParams"))
    linkObject.setIosExecutionParams(link.getString("iosExecutionParams"));
  return linkObject.build();
}
 
Example 14
Source File: RCTTwilioIPMessagingClient.java    From react-native-twilio-ip-messaging with MIT License 5 votes vote down vote up
@ReactMethod
public void createClient(ReadableMap props, final Promise promise) {
    final RCTTwilioIPMessagingClient tmp = RCTTwilioIPMessagingClient.getInstance();
    TwilioAccessManager accessManager = RCTTwilioAccessManager.getInstance().accessManager;

    TwilioIPMessagingClient.Properties.Builder builder = new TwilioIPMessagingClient.Properties.Builder();

    if (props != null) {
        if (props.hasKey("initialMessageCount")) {
            builder.setInitialMessageCount(props.getInt("initialMessageCount"));
        }
        if (props.hasKey("synchronizationStrategy")) {
            builder.setSynchronizationStrategy(TwilioIPMessagingClient.SynchronizationStrategy.valueOf(props.getString("synchronizationStrategy")));
        }
    }

    Constants.CallbackListener<TwilioIPMessagingClient> listener = new Constants.CallbackListener<TwilioIPMessagingClient>() {
        @Override
        public void onError(ErrorInfo errorInfo) {
            super.onError(errorInfo);
            promise.reject("create-client-error", "Error occurred while attempting to create the client. Error Message: " + errorInfo.getErrorText());
        }

        @Override
        public void onSuccess(TwilioIPMessagingClient twilioIPMessagingClient) {
            tmp.client = twilioIPMessagingClient;
            promise.resolve(RCTConvert.TwilioIPMessagingClient(tmp.client));
        }
    };
    tmp.client = TwilioIPMessagingSDK.createClient(accessManager, builder.createProperties(), listener);
    tmp.client.setListener(this);
}
 
Example 15
Source File: ReadableMapUtils.java    From react-native-google-cast with MIT License 5 votes vote down vote up
public static @Nullable ReadableMap getReadableMap(@NonNull ReadableMap map, @NonNull String key) {
    if (!map.hasKey(key)) {
        return null;
    }

    return map.getMap(key);
}
 
Example 16
Source File: FIRMessagingModule.java    From react-native-fcm with MIT License 4 votes vote down vote up
@ReactMethod
public void createNotificationChannel(ReadableMap details, Promise promise){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager mngr = (NotificationManager) getReactApplicationContext().getSystemService(NOTIFICATION_SERVICE);
        String id = details.getString("id");
        String name = details.getString("name");
        String priority = details.getString("priority");
        int importance;
        switch(priority) {
            case "min":
                importance = NotificationManager.IMPORTANCE_MIN;
                break;
            case "low":
                importance = NotificationManager.IMPORTANCE_LOW;
                break;
            case "high":
                importance = NotificationManager.IMPORTANCE_HIGH;
                break;
            case "max":
                importance = NotificationManager.IMPORTANCE_MAX;
                break;
            default:
                importance = NotificationManager.IMPORTANCE_DEFAULT;
        }
        if (mngr.getNotificationChannel(id) != null) {
            promise.resolve(null);
            return;
        }
        //
        NotificationChannel channel = new NotificationChannel(
                id,
                name,
                importance);
        // Configure the notification channel.
        if(details.hasKey("description")){
            channel.setDescription(details.getString("description"));
        }
        mngr.createNotificationChannel(channel);
    }
    promise.resolve(null);
}
 
Example 17
Source File: ShowOptions.java    From react-native-lock with MIT License 4 votes vote down vote up
public ShowOptions(@Nullable ReadableMap options) {
    if (options == null) {
        return;
    }

    if (options.hasKey(CLOSABLE_KEY)) {
        closable = options.getBoolean(CLOSABLE_KEY);
        Log.d(TAG, CLOSABLE_KEY + closable);
    }

    if (options.hasKey(DISABLE_SIGNUP)) {
         disableSignUp = options.getBoolean(DISABLE_SIGNUP);
         Log.d(TAG, DISABLE_SIGNUP + disableSignUp);
    }

    if (options.hasKey(DISABLE_RESET_PASSWORD)) {
         disableResetPassword = options.getBoolean(DISABLE_RESET_PASSWORD);
         Log.d(TAG, DISABLE_RESET_PASSWORD + disableResetPassword);
    }

    if (options.hasKey(USE_MAGIC_LINK_KEY)) {
        useMagicLink = options.getBoolean(USE_MAGIC_LINK_KEY);
        Log.d(TAG, USE_MAGIC_LINK_KEY + useMagicLink);
    }

    if (options.hasKey(AUTH_PARAMS_KEY)) {
        ReadableMap reactMap = options.getMap(AUTH_PARAMS_KEY);
        authParams = OptionsHelper.convertReadableMapToMap(reactMap);
        Log.d(TAG, AUTH_PARAMS_KEY + authParams);
    }

    if (options.hasKey(CONNECTIONS_KEY)) {
        ReadableArray connections = options.getArray(CONNECTIONS_KEY);
        List<String> list = new ArrayList<>(connections.size());
        for (int i = 0; i < connections.size(); i++) {
            String connectionName = connections.getString(i);
            switch (connectionName) {
                case LockReactModule.CONNECTION_EMAIL:
                    connectionType = LockReactModule.CONNECTION_EMAIL;
                    break;
                case LockReactModule.CONNECTION_SMS:
                    connectionType = LockReactModule.CONNECTION_SMS;
                    break;
            }
            list.add(connectionName);
        }
        this.connections = new String[list.size()];
        this.connections = list.toArray(this.connections);
        Log.d(TAG, CONNECTIONS_KEY + list);
    }
}
 
Example 18
Source File: RNPromptModule.java    From react-native-prompt-android with MIT License 4 votes vote down vote up
@ReactMethod
public void promptWithArgs(ReadableMap options, final Callback callback) {
    final FragmentManagerHelper fragmentManagerHelper = getFragmentManagerHelper();
    if (fragmentManagerHelper == null) {
        FLog.w(RNPromptModule.class, "Tried to show an alert while not attached to an Activity");
        return;
    }

    final Bundle args = new Bundle();
    if (options.hasKey(KEY_TITLE)) {
        args.putString(RNPromptFragment.ARG_TITLE, options.getString(KEY_TITLE));
    }
    if (options.hasKey(KEY_MESSAGE)) {
        String message = options.getString(KEY_MESSAGE);
        if (!message.isEmpty()) {
            args.putString(RNPromptFragment.ARG_MESSAGE, options.getString(KEY_MESSAGE));
        }
    }
    if (options.hasKey(KEY_BUTTON_POSITIVE)) {
        args.putString(RNPromptFragment.ARG_BUTTON_POSITIVE, options.getString(KEY_BUTTON_POSITIVE));
    }
    if (options.hasKey(KEY_BUTTON_NEGATIVE)) {
        args.putString(RNPromptFragment.ARG_BUTTON_NEGATIVE, options.getString(KEY_BUTTON_NEGATIVE));
    }
    if (options.hasKey(KEY_BUTTON_NEUTRAL)) {
        args.putString(RNPromptFragment.ARG_BUTTON_NEUTRAL, options.getString(KEY_BUTTON_NEUTRAL));
    }
    if (options.hasKey(KEY_ITEMS)) {
        ReadableArray items = options.getArray(KEY_ITEMS);
        CharSequence[] itemsArray = new CharSequence[items.size()];
        for (int i = 0; i < items.size(); i++) {
            itemsArray[i] = items.getString(i);
        }
        args.putCharSequenceArray(RNPromptFragment.ARG_ITEMS, itemsArray);
    }
    if (options.hasKey(KEY_CANCELABLE)) {
        args.putBoolean(KEY_CANCELABLE, options.getBoolean(KEY_CANCELABLE));
    }
    if (options.hasKey(KEY_TYPE)) {
        args.putString(KEY_TYPE, options.getString(KEY_TYPE));
    }
    if (options.hasKey(KEY_STYLE)) {
        args.putString(KEY_STYLE, options.getString(KEY_STYLE));
    }
    if (options.hasKey(KEY_DEFAULT_VALUE)) {
        args.putString(KEY_DEFAULT_VALUE, options.getString(KEY_DEFAULT_VALUE));
    }
    if (options.hasKey(KEY_PLACEHOLDER)) {
        args.putString(KEY_PLACEHOLDER, options.getString(KEY_PLACEHOLDER));
    }
    fragmentManagerHelper.showNewAlert(mIsInForeground, args, callback);
}
 
Example 19
Source File: ReactWebViewManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
@ReactProp(name = "source")
public void setSource(WebView view, @Nullable ReadableMap source) {
  if (source != null) {
    if (source.hasKey("html")) {
      String html = source.getString("html");
      if (source.hasKey("baseUrl")) {
        view.loadDataWithBaseURL(
          source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null);
      } else {
        view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
      }
      return;
    }
    if (source.hasKey("uri")) {
      String url = source.getString("uri");
      String previousUrl = view.getUrl();
      if (previousUrl != null && previousUrl.equals(url)) {
        return;
      }
      if (source.hasKey("method")) {
        String method = source.getString("method");
        if (method.equals(HTTP_METHOD_POST)) {
          byte[] postData = null;
          if (source.hasKey("body")) {
            String body = source.getString("body");
            try {
              postData = body.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
              postData = body.getBytes();
            }
          }
          if (postData == null) {
            postData = new byte[0];
          }
          view.postUrl(url, postData);
          return;
        }
      }
      HashMap<String, String> headerMap = new HashMap<>();
      if (source.hasKey("headers")) {
        ReadableMap headers = source.getMap("headers");
        ReadableMapKeySetIterator iter = headers.keySetIterator();
        while (iter.hasNextKey()) {
          String key = iter.nextKey();
          if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
            if (view.getSettings() != null) {
              view.getSettings().setUserAgentString(headers.getString(key));
            }
          } else {
            headerMap.put(key, headers.getString(key));
          }
        }
      }
      view.loadUrl(url, headerMap);
      return;
    }
  }
  view.loadUrl(BLANK_URL);
}
 
Example 20
Source File: RNFusedLocationModule.java    From react-native-geolocation-service with MIT License 4 votes vote down vote up
/**
 * Get the current position. This can return almost immediately if the location is cached or
 * request an update, which might take a while.
 *
 * @param options map containing optional arguments: timeout (millis), maximumAge (millis),
 *                highAccuracy (boolean), distanceFilter (double) and showLocationDialog (boolean)
 * @param success success callback
 * @param error   error callback
 */
@ReactMethod
public void getCurrentPosition(ReadableMap options, final Callback success, final Callback error) {
  ReactApplicationContext context = getContext();

  mSuccessCallback = success;
  mErrorCallback = error;

  if (!LocationUtils.hasLocationPermission(context)) {
    invokeError(
      LocationError.PERMISSION_DENIED.getValue(),
      "Location permission not granted.",
      true
    );
    return;
  }

  if (!LocationUtils.isGooglePlayServicesAvailable(context)) {
    invokeError(
      LocationError.PLAY_SERVICE_NOT_AVAILABLE.getValue(),
      "Google play service is not available.",
      true
    );
    return;
  }

  boolean highAccuracy = options.hasKey("enableHighAccuracy") &&
    options.getBoolean("enableHighAccuracy");

  // TODO: Make other PRIORITY_* constants available to the user
  mLocationPriority = highAccuracy ? LocationRequest.PRIORITY_HIGH_ACCURACY : DEFAULT_ACCURACY;

  mTimeout = options.hasKey("timeout") ? (long) options.getDouble("timeout") : Long.MAX_VALUE;
  mMaximumAge = options.hasKey("maximumAge")
    ? options.getDouble("maximumAge")
    : Double.POSITIVE_INFINITY;
  mDistanceFilter = options.hasKey("distanceFilter")
    ? (float) options.getDouble("distanceFilter")
    : 0;
  mShowLocationDialog = options.hasKey("showLocationDialog")
    ? options.getBoolean("showLocationDialog")
    : true;
  mForceRequestLocation = options.hasKey("forceRequestLocation")
    ? options.getBoolean("forceRequestLocation")
    : false;

  LocationSettingsRequest locationSettingsRequest = buildLocationSettingsRequest();

  if (mSettingsClient != null) {
    mSettingsClient.checkLocationSettings(locationSettingsRequest)
      .addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
        @Override
        public void onComplete(@NonNull Task<LocationSettingsResponse> task) {
          onLocationSettingsResponse(task, true);
        }
      });
  }
}