本文整理匯總了Java中com.facebook.react.bridge.ReactContext類的典型用法代碼示例。如果您正苦於以下問題:Java ReactContext類的具體用法?Java ReactContext怎麽用?Java ReactContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ReactContext類屬於com.facebook.react.bridge包,在下文中一共展示了ReactContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: waitForJSIdle
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
private static void waitForJSIdle(ReactContext reactContext) {
if (!reactContext.hasActiveCatalystInstance()) {
return;
}
final CountDownLatch latch = new CountDownLatch(1);
reactContext.runOnJSQueueThread(
new Runnable() {
@Override
public void run() {
latch.countDown();
}
});
try {
if (!latch.await(5000, TimeUnit.MILLISECONDS)) {
throw new RuntimeException("Timed out waiting for JS thread");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例2: startTask
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
/**
* Start a JS task. Handles invoking {@link AppRegistry#startHeadlessTask} and notifying
* listeners.
*
* @return a unique id representing this task instance.
*/
public synchronized int startTask(final HeadlessJsTaskConfig taskConfig) {
UiThreadUtil.assertOnUiThread();
ReactContext reactContext = Assertions.assertNotNull(
mReactContext.get(),
"Tried to start a task on a react context that has already been destroyed");
if (reactContext.getLifecycleState() == LifecycleState.RESUMED &&
!taskConfig.isAllowedInForeground()) {
throw new IllegalStateException(
"Tried to start task " + taskConfig.getTaskKey() +
" while in foreground, but this is not allowed.");
}
final int taskId = mLastTaskId.incrementAndGet();
mActiveTasks.add(taskId);
reactContext.getJSModule(AppRegistry.class)
.startHeadlessTask(taskId, taskConfig.getTaskKey(), taskConfig.getData());
if (taskConfig.getTimeout() > 0) {
scheduleTaskTimeout(taskId, taskConfig.getTimeout());
}
for (HeadlessJsTaskEventListener listener : mHeadlessJsTaskEventListeners) {
listener.onHeadlessJsTaskStart(taskId);
}
return taskId;
}
示例3: emitScrollEvent
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
private static void emitScrollEvent(ViewGroup scrollView, ScrollEventType scrollEventType) {
View contentView = scrollView.getChildAt(0);
if (contentView == null) {
return;
}
ReactContext reactContext = (ReactContext) scrollView.getContext();
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
ScrollEvent.obtain(
scrollView.getId(),
scrollEventType,
scrollView.getScrollX(),
scrollView.getScrollY(),
contentView.getWidth(),
contentView.getHeight(),
scrollView.getWidth(),
scrollView.getHeight()));
}
示例4: SocketClient
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
SocketClient(ReadableMap params, ReactContext reactContext) {
//String addr, int port, boolean autoReconnect
mReactContext = reactContext;
dstAddress = params.getString("address");
dstPort = params.getInt("port");
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();
}
示例5: CropTask
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
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;
}
示例6: setup
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
void setup(ReactContext reactContext) {
this.setOrientation(VERTICAL);
this.reactViewPager = new ReactViewPager(reactContext);
this.reactViewPager.setParentIdCallback(new ReactViewPager.ParentIdCallback() {
@Override public int getParentId() {
return getId();
}
});
this.tabLayout = new TabLayout(reactContext);
this.tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
LayoutParams viewPagerParams =
new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
1);
LayoutParams tabParams =
new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
this.addView(tabLayout, tabParams);
this.addView(reactViewPager, viewPagerParams);
tabLayout.setupWithViewPager(reactViewPager);
}
示例7: callJavaScript
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
@ReactMethod
void callJavaScript() {
Activity activity = getCurrentActivity();
if (activity != null) {
MainApplication application = (MainApplication) activity.getApplication();
ReactNativeHost reactNativeHost = application.getReactNativeHost();
ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
if (reactContext != null) {
CatalystInstance catalystInstance = reactContext.getCatalystInstance();
WritableNativeArray params = new WritableNativeArray();
params.pushString("Hello, JavaScript!");
catalystInstance.callFunction("JavaScriptVisibleToJava", "alert", params);
}
}
}
示例8: onDestroy
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
@Override
public void onDestroy() {
super.onDestroy();
if (getReactNativeHost().hasInstance()) {
ReactInstanceManager reactInstanceManager = getReactNativeHost().getReactInstanceManager();
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
if (reactContext != null) {
HeadlessJsTaskContext headlessJsTaskContext =
HeadlessJsTaskContext.getInstance(reactContext);
headlessJsTaskContext.removeTaskEventListener(this);
}
}
if (sWakeLock != null) {
sWakeLock.release();
}
}
示例9: onSizeChanged
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
@Override
protected void onSizeChanged(final int w, final int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (getChildCount() > 0) {
final int viewTag = getChildAt(0).getId();
ReactContext reactContext = (ReactContext) getContext();
reactContext.runOnNativeModulesQueueThread(
new GuardedRunnable(reactContext) {
@Override
public void runGuarded() {
((ReactContext) getContext()).getNativeModule(UIManagerModule.class)
.updateNodeSize(viewTag, w, h);
}
});
}
}
示例10: getDefaultConfigBuilder
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
/**
* Get the default Fresco configuration builder.
* Allows adding of configuration options in addition to the default values.
*
* @return {@link ImagePipelineConfig.Builder} that has been initialized with default values
*/
public static ImagePipelineConfig.Builder getDefaultConfigBuilder(ReactContext context) {
HashSet<RequestListener> requestListeners = new HashSet<>();
requestListeners.add(new SystraceRequestListener());
OkHttpClient client = OkHttpClientProvider.createClient();
// make sure to forward cookies for any requests via the okHttpClient
// so that image requests to endpoints that use cookies still work
CookieJarContainer container = (CookieJarContainer) client.cookieJar();
ForwardingCookieHandler handler = new ForwardingCookieHandler(context);
container.setCookieJar(new JavaNetCookieJar(handler));
return OkHttpImagePipelineConfigFactory
.newBuilder(context.getApplicationContext(), client)
.setNetworkFetcher(new ReactOkHttpNetworkFetcher(client))
.setDownsampleEnabled(false)
.setRequestListeners(requestListeners);
}
示例11: shutDownContext
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
public void shutDownContext() {
if (mInstance != null) {
final ReactContext contextToDestroy = mReactContext;
mReactContext = null;
mInstance = null;
final SimpleSettableFuture<Void> semaphore = new SimpleSettableFuture<>();
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
if (contextToDestroy != null) {
contextToDestroy.destroy();
}
semaphore.set(null);
}
});
semaphore.getOrThrow();
}
}
示例12: waitForBridgeAndUIIdle
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
/**
* Waits for both the UI thread and bridge to be idle. It determines this by waiting for the
* bridge to become idle, then waiting for the UI thread to become idle, then checking if the
* bridge is idle again (if the bridge was idle before and is still idle after running the UI
* thread to idle, then there are no more events to process in either place).
* <p/>
* Also waits for any Choreographer callbacks to run after the initial sync since things like UI
* events are initiated from Choreographer callbacks.
*/
public static void waitForBridgeAndUIIdle(
ReactBridgeIdleSignaler idleSignaler,
final ReactContext reactContext,
long timeoutMs) {
UiThreadUtil.assertNotOnUiThread();
long startTime = SystemClock.uptimeMillis();
waitInner(idleSignaler, timeoutMs);
long timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
waitForChoreographer(timeToWait);
waitForJSIdle(reactContext);
timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
waitInner(idleSignaler, timeToWait);
timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
waitForChoreographer(timeToWait);
}
示例13: handleSuccess
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
private void handleSuccess() {
WritableMap evt = Arguments.createMap();
ReactContext ctx = (ReactContext) getContext();
ctx.getJSModule(RCTEventEmitter.class).receiveEvent(
getId(),
"onLoadSuccess",
evt);
}
示例14: onSizeChanged
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
@Override
public void onSizeChanged(TweetView view, final int width, final int height) {
Log.d(TAG, "TweetView changed size: " + width + ", " + height);
ReactContext ctx = (ReactContext) view.getContext();
final UIManagerModule uiManager = ctx.getNativeModule(UIManagerModule.class);
final int reactTag = view.getReactTag();
ctx.runOnNativeModulesQueueThread(new Runnable() {
@Override
public void run() {
uiManager.updateNodeSize(reactTag, width, height);
}
});
}
示例15: onOffsetChanged
import com.facebook.react.bridge.ReactContext; //導入依賴的package包/類
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
WritableMap event = Arguments.createMap();
event.putDouble("offset", verticalOffset);
ReactContext reactContext = (ReactContext) appBarLayout.getContext();
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(appBarLayout.getId(), "topOffsetChanged", event);
}