support api 15 (use Handler-backed ui driven).

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
This commit is contained in:
desmondyao
2017-02-27 04:20:51 -08:00
committed by Facebook Github Bot
parent 8b01508410
commit 20ad2b3fbb
18 changed files with 260 additions and 149 deletions

View File

@@ -9,20 +9,19 @@
package com.facebook.react.uimanager;
import android.view.Choreographer;
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 GuardedChoreographerFrameCallback implements Choreographer.FrameCallback {
public abstract class GuardedFrameCallback extends ChoreographerCompat.FrameCallback {
private final ReactContext mReactContext;
protected GuardedChoreographerFrameCallback(ReactContext reactContext) {
protected GuardedFrameCallback(ReactContext reactContext) {
mReactContext = reactContext;
}

View File

@@ -722,8 +722,7 @@ public class UIViewOperationQueue {
final int reactTag,
final Callback callback) {
mOperations.add(
new MeasureInWindowOperation(reactTag, callback)
);
new MeasureInWindowOperation(reactTag, callback));
}
public void enqueueFindTargetForTouch(
@@ -862,7 +861,7 @@ public class UIViewOperationQueue {
* Using a Choreographer callback (which runs immediately before traversals), we guarantee we run
* before the next traversal.
*/
private class DispatchUIFrameCallback extends GuardedChoreographerFrameCallback {
private class DispatchUIFrameCallback extends GuardedFrameCallback {
private static final int MIN_TIME_LEFT_IN_FRAME_TO_SCHEDULE_MORE_WORK_MS = 8;
private static final int FRAME_TIME_MS = 16;

View File

@@ -17,13 +17,13 @@ import java.util.Comparator;
import java.util.Map;
import android.util.LongSparseArray;
import android.view.Choreographer;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.modules.core.ChoreographerCompat;
import com.facebook.react.modules.core.ReactChoreographer;
import com.facebook.systrace.Systrace;
@@ -251,7 +251,7 @@ public class EventDispatcher implements LifecycleEventListener {
(((long) coalescingKey) & 0xffff) << 48;
}
private class ScheduleDispatchFrameCallback implements Choreographer.FrameCallback {
private class ScheduleDispatchFrameCallback extends ChoreographerCompat.FrameCallback {
private volatile boolean mIsPosted = false;
private boolean mShouldStop = false;