Java Code Examples for com.facebook.react.uimanager.events.EventDispatcher#dispatchEvent()

The following examples show how to use com.facebook.react.uimanager.events.EventDispatcher#dispatchEvent() . 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: ReactAztecText.java    From react-native-aztec with GNU General Public License v2.0 6 votes vote down vote up
private boolean onBackspace() {
    int cursorPositionStart = getSelectionStart();
    int cursorPositionEnd = getSelectionEnd();
    // Make sure to report backspace at the beginning only, with no selection.
    if (cursorPositionStart != 0 || cursorPositionEnd != 0) {
        return false;
    }

    disableTextChangedListener();
    String content = toHtml(false);
    enableTextChangedListener();
    ReactContext reactContext = (ReactContext) getContext();
    EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
    // TODO: isRTL? Should be passed here?
    eventDispatcher.dispatchEvent(
            new ReactAztecBackspaceEvent(getId(), content, cursorPositionStart, cursorPositionEnd)
    );
    return true;
}
 
Example 2
Source File: ReactAztecText.java    From react-native-aztec with GNU General Public License v2.0 5 votes vote down vote up
private void updateToolbarButtons(ArrayList<ITextFormat> appliedStyles) {
    // Read the applied styles and get the String list of formatting options
    LinkedList<String> formattingOptions = new LinkedList<>();
    for (ITextFormat currentStyle : appliedStyles) {
        if ((currentStyle == AztecTextFormat.FORMAT_STRONG || currentStyle == AztecTextFormat.FORMAT_BOLD)
                && !formattingOptions.contains("bold")) {
            formattingOptions.add("bold");
        }
        if ((currentStyle == AztecTextFormat.FORMAT_ITALIC || currentStyle == AztecTextFormat.FORMAT_CITE)
                && !formattingOptions.contains("italic")) {
            formattingOptions.add("italic");
        }
        if (currentStyle == AztecTextFormat.FORMAT_STRIKETHROUGH) {
            formattingOptions.add("strikethrough");
        }
    }

    // Check if the same formatting event was already sent
    String newOptionsAsString = "";
    for (String currentFormatting: formattingOptions) {
        newOptionsAsString += currentFormatting;
    }
    if (newOptionsAsString.equals(lastSentFormattingOptionsEventString)) {
        // no need to send any event now
        return;
    }
    lastSentFormattingOptionsEventString = newOptionsAsString;

    if (shouldHandleActiveFormatsChange) {
        ReactContext reactContext = (ReactContext) getContext();
        EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
        eventDispatcher.dispatchEvent(
                new ReactAztecFormattingChangeEvent(
                        getId(),
                        formattingOptions.toArray(new String[formattingOptions.size()])
                )
        );
    }
}
 
Example 3
Source File: ReactAztecText.java    From react-native-aztec with GNU General Public License v2.0 5 votes vote down vote up
private void propagateSelectionChanges(int selStart, int selEnd) {
    if (!shouldHandleOnSelectionChange) {
        return;
    }
    String content = toHtml(false);
    ReactContext reactContext = (ReactContext) getContext();
    EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
    eventDispatcher.dispatchEvent(
            new ReactAztecSelectionChangeEvent(getId(), content, selStart, selEnd)
    );
}
 
Example 4
Source File: ReactAztecText.java    From react-native-aztec with GNU General Public License v2.0 5 votes vote down vote up
private boolean onEnter() {
    disableTextChangedListener();
    String content = toHtml(false);
    int cursorPositionStart = getSelectionStart();
    int cursorPositionEnd = getSelectionEnd();
    enableTextChangedListener();
    ReactContext reactContext = (ReactContext) getContext();
    EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
    eventDispatcher.dispatchEvent(
            new ReactAztecEnterEvent(getId(), content, cursorPositionStart, cursorPositionEnd)
    );
    return true;
}
 
Example 5
Source File: ReactImageView.java    From react-native-GPay with MIT License 5 votes vote down vote up
public void setShouldNotifyLoadEvents(boolean shouldNotify) {
  if (!shouldNotify) {
    mControllerListener = null;
  } else {
    final EventDispatcher mEventDispatcher = ((ReactContext) getContext()).getNativeModule(UIManagerModule.class).getEventDispatcher();

    mControllerListener = new BaseControllerListener<ImageInfo>() {
      @Override
      public void onSubmit(String id, Object callerContext) {
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_START));
      }

      @Override
      public void onFinalImageSet(
        String id,
        @Nullable final ImageInfo imageInfo,
        @Nullable Animatable animatable) {
        if (imageInfo != null) {
          mEventDispatcher.dispatchEvent(
            new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD,
              mImageSource.getSource(), imageInfo.getWidth(), imageInfo.getHeight()));
          mEventDispatcher.dispatchEvent(
            new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END));
        }
      }

      @Override
      public void onFailure(String id, Throwable throwable) {
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_ERROR));
        mEventDispatcher.dispatchEvent(
          new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END));
      }
    };
  }

  mIsDirty = true;
}
 
Example 6
Source File: ReactAztecText.java    From react-native-aztec with GNU General Public License v2.0 4 votes vote down vote up
public void applyFormat(String format) {
    ArrayList<ITextFormat> newFormats = new ArrayList<>();
    switch (format) {
        case ("bold"):
        case ("strong"):
            newFormats.add(AztecTextFormat.FORMAT_STRONG);
            newFormats.add(AztecTextFormat.FORMAT_BOLD);
        break;
        case ("italic"):
            newFormats.add(AztecTextFormat.FORMAT_ITALIC);
            newFormats.add(AztecTextFormat.FORMAT_CITE);
        break;
        case ("strikethrough"):
            newFormats.add(AztecTextFormat.FORMAT_STRIKETHROUGH);
        break;
    }

    if (newFormats.size() == 0) {
        return;
    }

    if (!isTextSelected()) {
        final ArrayList<ITextFormat> newStylesList = getNewStylesList(newFormats);
        setSelectedStyles(newStylesList);
        // Update the toolbar state
        updateToolbarButtons(newStylesList);
    } else {
        toggleFormatting(newFormats.get(0));
        // Update the toolbar state
        updateToolbarButtons(getSelectionStart(), getSelectionEnd());
    }

    // emit onChange because the underlying HTML has changed applying the style
    ReactContext reactContext = (ReactContext) getContext();
    EventDispatcher eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
    eventDispatcher.dispatchEvent(
            new ReactTextChangedEvent(
                    getId(),
                    toHtml(false),
                    incrementAndGetEventCounter())
    );
}
 
Example 7
Source File: Web3WebviewManager.java    From react-native-web3-webview with MIT License 4 votes vote down vote up
protected static void dispatchEvent(WebView webView, Event event) {
    ReactContext reactContext = (ReactContext) webView.getContext();
    EventDispatcher eventDispatcher =
            reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
    eventDispatcher.dispatchEvent(event);
}
 
Example 8
Source File: ReactWebViewManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
protected static void dispatchEvent(WebView webView, Event event) {
  ReactContext reactContext = (ReactContext) webView.getContext();
  EventDispatcher eventDispatcher =
    reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
  eventDispatcher.dispatchEvent(event);
}
 
Example 9
Source File: RNX5WebViewManager.java    From react-native-x5 with MIT License 4 votes vote down vote up
private static void dispatchEvent(WebView webView, Event event) {
    ReactContext reactContext = (ReactContext) webView.getContext();
    EventDispatcher eventDispatcher =
            reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
    eventDispatcher.dispatchEvent(event);
}