mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-10 11:26:51 +08:00
Summary: Android API 15 still have 1.5~2.0% distribution (refer: [Dashboard - Android Developer](https://developer.android.com/ndk/guides/standalone_toolchain.html#creating_the_toolchain)). React Native is a good tec but many companies cannot endure loose their consumer. [Choreographer](https://developer.android.com/reference/android/view/Choreographer.html) triggered UI operation is the only reason that React Native Android sdk use minSdkVersion 16, so we can use a backward solution **only in API 15**: [Handler](https://developer.android.com/reference/android/os/Handler.html). In this PR, the biggest change is : - Make core operation of ReactChoreographer to an interface: ReactUIDriver; - Impl ReactUIDriver by Handler => UIDriverHandlerImpl, refactor ReactChoreographer to UIDriverChoreographerImpl; - Let UIDriverFactory to choose which one impl would be in use. (Only use handler in api 15). Closes https://github.com/facebook/react-native/pull/12396 Reviewed By: AaaChiuuu Differential Revision: D4588399 Pulled By: astreet fbshipit-source-id: 76408e53664314dd926e6a553cde6bafbd37779e
43 lines
1.3 KiB
Java
43 lines
1.3 KiB
Java
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
package com.facebook.react.uimanager;
|
|
|
|
import com.facebook.react.bridge.ReactContext;
|
|
import com.facebook.react.modules.core.ChoreographerCompat;
|
|
|
|
/**
|
|
* Abstract base for a Choreographer FrameCallback that should have any RuntimeExceptions it throws
|
|
* handled by the {@link com.facebook.react.bridge.NativeModuleCallExceptionHandler} registered if
|
|
* the app is in dev mode.
|
|
*/
|
|
public abstract class GuardedFrameCallback extends ChoreographerCompat.FrameCallback {
|
|
|
|
private final ReactContext mReactContext;
|
|
|
|
protected GuardedFrameCallback(ReactContext reactContext) {
|
|
mReactContext = reactContext;
|
|
}
|
|
|
|
@Override
|
|
public final void doFrame(long frameTimeNanos) {
|
|
try {
|
|
doFrameGuarded(frameTimeNanos);
|
|
} catch (RuntimeException e) {
|
|
mReactContext.handleException(e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Like the standard doFrame but RuntimeExceptions will be caught and passed to
|
|
* {@link com.facebook.react.bridge.ReactContext#handleException(RuntimeException)}.
|
|
*/
|
|
protected abstract void doFrameGuarded(long frameTimeNanos);
|
|
}
|