com.facebook.react.common.build.ReactBuildConfig Java Examples

The following examples show how to use com.facebook.react.common.build.ReactBuildConfig. 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: RNX5WebViewManager.java    From react-native-x5 with MIT License 6 votes vote down vote up
@Override
protected WebView createViewInstance(ThemedReactContext reactContext) {
    X5WeView webView = new X5WeView(reactContext);

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissionsCallback callback) {
            callback.invoke(origin, true, false);
        }
    });
    reactContext.addLifecycleEventListener(webView);
    mWebViewConfig.configWebView(webView);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);

    // Fixes broken full-screen modals/galleries due to body height being 0.
    webView.setLayoutParams(
            new LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.MATCH_PARENT));

    if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    return webView;
}
 
Example #2
Source File: JavaScriptModuleRegistry.java    From react-native-GPay with MIT License 6 votes vote down vote up
public JavaScriptModuleInvocationHandler(
    CatalystInstance catalystInstance,
    Class<? extends JavaScriptModule> moduleInterface) {
  mCatalystInstance = catalystInstance;
  mModuleInterface = moduleInterface;

  if (ReactBuildConfig.DEBUG) {
    Set<String> methodNames = new HashSet<>();
    for (Method method : mModuleInterface.getDeclaredMethods()) {
      if (!methodNames.add(method.getName())) {
        throw new AssertionError(
          "Method overloading is unsupported: " + mModuleInterface.getName() +
            "#" + method.getName());
      }
    }
  }
}
 
Example #3
Source File: RNX5WebViewManager.java    From react-native-x5 with MIT License 6 votes vote down vote up
public void linkBridge() {
    if (messagingEnabled) {
        if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            // See isNative in lodash
            String testPostMessageNative = "String(window.postMessage) === String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage')";
            evaluateJavascript(testPostMessageNative, new ValueCallback<String>() {
                @Override
                public void onReceiveValue(String value) {
                    if (value.equals("true")) {
                        FLog.w(ReactConstants.TAG, "Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined");
                    }
                }
            });
        }

        loadUrl("javascript:(" +
                "window.originalPostMessage = window.postMessage," +
                "window.postMessage = function(data) {" +
                BRIDGE_NAME + ".postMessage(String(data));" +
                "}" +
                ")");
    }
}
 
Example #4
Source File: ReactWebViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
public void linkBridge() {
  if (messagingEnabled) {
    if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      // See isNative in lodash
      String testPostMessageNative = "String(window.postMessage) === String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage')";
      evaluateJavascript(testPostMessageNative, new ValueCallback<String>() {
        @Override
        public void onReceiveValue(String value) {
          if (value.equals("true")) {
            FLog.w(ReactConstants.TAG, "Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined");
          }
        }
      });
    }

    evaluateJavascriptWithFallback("(" +
      "window.originalPostMessage = window.postMessage," +
      "window.postMessage = function(data) {" +
      BRIDGE_NAME + ".postMessage(String(data));" +
      "}" +
      ")");
  }
}
 
Example #5
Source File: ReactImageView.java    From react-native-GPay with MIT License 5 votes vote down vote up
private void warnImageSource(String uri) {
  if (ReactBuildConfig.DEBUG) {
    Toast.makeText(
      getContext(),
      "Warning: Image source \"" + uri + "\" doesn't exist",
      Toast.LENGTH_SHORT).show();
  }
}
 
Example #6
Source File: ModuleSpec.java    From react-native-GPay with MIT License 5 votes vote down vote up
public ConstructorProvider(Class<? extends NativeModule> type, Class[] signature) {
  if (ReactBuildConfig.DEBUG) {
    try {
      mConstructor = getConstructor(type, signature);
    } catch (NoSuchMethodException e) {
      throw new IllegalArgumentException("No such constructor", e);
    }
  }
}
 
Example #7
Source File: MagnetWebViewManager.java    From magnet-client with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected WebView createViewInstance(ThemedReactContext reactContext) {
    MagnetWebView magnetWebView = new MagnetWebView(mContext);
    reactContext.addLifecycleEventListener(magnetWebView);

    if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    return magnetWebView;
}
 
Example #8
Source File: ReactTestAppShell.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
protected void onBaseContextAttached() {
  // This is a terrible hack.  Don't copy it.
  // It's unfortunate that Instagram does the same thing.
  // We need to do this here because internal apps use SoLoader,
  // and Open Source Buck uses ExopackageSoLoader.
  // If you feel the need to copy this, we should refactor it
  // into an FB-specific subclass of ExopackageApplication.
  SoLoader.init(this, (ReactBuildConfig.EXOPACKAGE_FLAGS & 2) != 0);
}
 
Example #9
Source File: ModuleSpecTest.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Test
public void testSimpleContextConstructor() {
  Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", true);
  ReactApplicationContext context = mock(ReactApplicationContext.class);
  ModuleSpec spec = ModuleSpec.simple(SimpleContextModule.class, context);

  NativeModule module = spec.getProvider().get();
  assertThat(module).isInstanceOf(SimpleContextModule.class);
  SimpleContextModule contextModule = (SimpleContextModule) module;
  assertThat(contextModule.getReactApplicationContext()).isSameAs(context);
}
 
Example #10
Source File: ModuleSpecTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testSimpleFailFast() {
  Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", true);
  ModuleSpec.simple(ComplexModule.class, mock(ReactApplicationContext.class));
}
 
Example #11
Source File: ModuleSpecTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Test
public void testSimpleDefaultConstructor() {
  Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", true);
  ModuleSpec spec = ModuleSpec.simple(SimpleModule.class);
  assertThat(spec.getProvider().get()).isInstanceOf(SimpleModule.class);
}
 
Example #12
Source File: ModuleSpecTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testSimpleFailLateRelease() {
  Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", false);
  ModuleSpec spec = ModuleSpec.simple(ComplexModule.class, mock(ReactApplicationContext.class));
  spec.getProvider().get();
}
 
Example #13
Source File: ModuleSpecTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Test
public void testSimpleNoFailFastRelease() {
  Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", false);
  ModuleSpec.simple(ComplexModule.class, mock(ReactApplicationContext.class));
}
 
Example #14
Source File: ModuleSpecTest.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testSimpleFailFastDefault() {
  Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", true);
  ModuleSpec.simple(ComplexModule.class);
}
 
Example #15
Source File: ReactTestAppShell.java    From react-native-GPay with MIT License 4 votes vote down vote up
public ReactTestAppShell() {
  super("com.facebook.react.testing.ReactTestApplicationImpl", ReactBuildConfig.EXOPACKAGE_FLAGS);
}
 
Example #16
Source File: DevInternalSettings.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Override
public boolean isNuclideJSDebugEnabled() {
  return ReactBuildConfig.IS_INTERNAL_BUILD && ReactBuildConfig.DEBUG;
}
 
Example #17
Source File: ReactWebViewManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected WebView createViewInstance(ThemedReactContext reactContext) {
  ReactWebView webView = createReactWebViewInstance(reactContext);
  webView.setWebChromeClient(new WebChromeClient() {
    @Override
    public boolean onConsoleMessage(ConsoleMessage message) {
      if (ReactBuildConfig.DEBUG) {
        return super.onConsoleMessage(message);
      }
      // Ignore console logs in non debug builds.
      return true;
    }

    @Override
    public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
      callback.invoke(origin, true, false);
    }
  });
  reactContext.addLifecycleEventListener(webView);
  mWebViewConfig.configWebView(webView);
  WebSettings settings = webView.getSettings();
  settings.setBuiltInZoomControls(true);
  settings.setDisplayZoomControls(false);
  settings.setDomStorageEnabled(true);

  settings.setAllowFileAccess(false);
  settings.setAllowContentAccess(false);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    settings.setAllowFileAccessFromFileURLs(false);
    setAllowUniversalAccessFromFileURLs(webView, false);
  }
  setMixedContentMode(webView, "never");

  // Fixes broken full-screen modals/galleries due to body height being 0.
  webView.setLayoutParams(
    new LayoutParams(LayoutParams.MATCH_PARENT,
      LayoutParams.MATCH_PARENT));

  setGeolocationEnabled(webView, false);
  if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    WebView.setWebContentsDebuggingEnabled(true);
  }

  return webView;
}