react-native-navigation的迁移库

NativeCommandListener.java 961B

1234567891011121314151617181920212223242526272829303132
  1. package com.reactnativenavigation.utils;
  2. import android.support.annotation.Nullable;
  3. import com.facebook.react.bridge.Promise;
  4. import com.reactnativenavigation.react.EventEmitter;
  5. public class NativeCommandListener extends CommandListenerAdapter {
  6. private String commandId;
  7. @Nullable private Promise promise;
  8. private EventEmitter eventEmitter;
  9. private Now now;
  10. public NativeCommandListener(String commandId, @Nullable Promise promise, EventEmitter eventEmitter, Now now) {
  11. this.commandId = commandId;
  12. this.promise = promise;
  13. this.eventEmitter = eventEmitter;
  14. this.now = now;
  15. }
  16. @Override
  17. public void onSuccess(String childId) {
  18. if (promise != null) promise.resolve(childId);
  19. eventEmitter.emitCommandCompletedEvent(commandId, now.now());
  20. }
  21. @Override
  22. public void onError(String message) {
  23. if (promise != null) promise.reject(new Throwable(message));
  24. }
  25. }