Java Code Examples for com.facebook.react.uimanager.UIManagerModule#addUIBlock()

The following examples show how to use com.facebook.react.uimanager.UIManagerModule#addUIBlock() . 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: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 7 votes vote down vote up
@ReactMethod
public void play(final int reactTag) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.play();
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example 2
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void setPlaylistIndex(final int reactTag, final int index) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.setCurrentAudioTrack(index);
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example 3
Source File: YouTubeModule.java    From react-native-youtube with MIT License 6 votes vote down vote up
@ReactMethod
public void getDuration(final int reactTag, final Promise promise) {
    try {
        UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
        uiManager.addUIBlock(new UIBlock() {
            public void execute (NativeViewHierarchyManager nvhm) {
                YouTubeView youTubeView = (YouTubeView) nvhm.resolveView(reactTag);
                YouTubeManager youTubeManager = (YouTubeManager) nvhm.resolveViewManager(reactTag);
                int duration = youTubeManager.getDuration(youTubeView);
                promise.resolve(duration);
            }
        });
    } catch (IllegalViewOperationException e) {
        promise.reject(E_MODULE_ERROR, e);
    }
}
 
Example 4
Source File: YouTubeModule.java    From react-native-youtube with MIT License 6 votes vote down vote up
@ReactMethod
public void getCurrentTime(final int reactTag, final Promise promise) {
    try {
        UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
        uiManager.addUIBlock(new UIBlock() {
            public void execute (NativeViewHierarchyManager nvhm) {
                YouTubeView youTubeView = (YouTubeView) nvhm.resolveView(reactTag);
                YouTubeManager youTubeManager = (YouTubeManager) nvhm.resolveViewManager(reactTag);
                int currentTime = youTubeManager.getCurrentTime(youTubeView);
                promise.resolve(currentTime);
            }
        });
    } catch (IllegalViewOperationException e) {
        promise.reject(E_MODULE_ERROR, e);
    }
}
 
Example 5
Source File: YouTubeModule.java    From react-native-youtube with MIT License 6 votes vote down vote up
@ReactMethod
public void getVideosIndex(final int reactTag, final Promise promise) {
    try {
        UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
        uiManager.addUIBlock(new UIBlock() {
            public void execute (NativeViewHierarchyManager nvhm) {
                YouTubeView youTubeView = (YouTubeView) nvhm.resolveView(reactTag);
                YouTubeManager youTubeManager = (YouTubeManager) nvhm.resolveViewManager(reactTag);
                int index = youTubeManager.getVideosIndex(youTubeView);
                promise.resolve(index);
            }
        });
    } catch (IllegalViewOperationException e) {
        promise.reject(E_MODULE_ERROR, e);
    }
}
 
Example 6
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void setFullscreen(final int reactTag, final boolean fullscreen) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.setFullscreen(fullscreen, fullscreen);
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example 7
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void state(final int reactTag, final Promise promise) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          PlayerState playerState = playerView.mPlayer.getState();
          promise.resolve(stateToInt(playerState));
        } else {
          promise.reject("RNJW Error", "Player is null");
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    promise.reject("RNJW Error", e);
  }
}
 
Example 8
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void position(final int reactTag, final Promise promise) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          promise.resolve((Double.valueOf(playerView.mPlayer.getPosition()).intValue()));
        } else {
          promise.reject("RNJW Error", "Player is null");
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    promise.reject("RNJW Error", e);
  }
}
 
Example 9
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void setControls(final int reactTag, final boolean show) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.setControls(show);
          playerView.mPlayer.getConfig().setControls(show);
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example 10
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void seekTo(final int reactTag, final double time) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.seek(time);
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example 11
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void stop(final int reactTag) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.stop();
          playerView.userPaused = true;
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example 12
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void pause(final int reactTag) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.pause();
          playerView.userPaused = true;
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example 13
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void setSpeed(final int reactTag, final float speed) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          playerView.mPlayer.setPlaybackRate(speed);
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example 14
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 6 votes vote down vote up
@ReactMethod
public void toggleSpeed(final int reactTag) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playerView != null && playerView.mPlayer != null) {
          float rate = playerView.mPlayer.getPlaybackRate();
          if (rate < 2) {
            playerView.mPlayer.setPlaybackRate(rate += 0.5);
          } else {
            playerView.mPlayer.setPlaybackRate((float) 0.5);
          }
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example 15
Source File: RNArcGISMapViewModule.java    From react-native-arcgis-mapview with MIT License 5 votes vote down vote up
@ReactMethod
public void getRouteIsVisible(final int viewId, final Callback callback) {
    UIManagerModule uiManagerModule = getReactApplicationContext().getNativeModule(UIManagerModule.class);
    uiManagerModule.addUIBlock(nativeViewHierarchyManager -> {
        View view = nativeViewHierarchyManager.resolveView(viewId);
        if (view instanceof RNAGSMapView) {
            Boolean result = ((RNAGSMapView) view).getRouteIsVisible();
            callback.invoke(result);
        }
    });
}
 
Example 16
Source File: YouTubeSdkModule.java    From react-native-youtube-sdk with Apache License 2.0 5 votes vote down vote up
@ReactMethod
public void getVideoDuration(final int reactTag, final Promise promise) {
  try {
    UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(nvhm -> {
      YouTubeView youTubeView = (YouTubeView) nvhm.resolveView(reactTag);
      promise.resolve(youTubeView.getYouTubePlayerProps().getTracker().getVideoDuration());
    });
  } catch (IllegalViewOperationException e) {
    promise.reject("getVideoDuration", e);
  }
}
 
Example 17
Source File: YouTubeSdkModule.java    From react-native-youtube-sdk with Apache License 2.0 5 votes vote down vote up
@ReactMethod
public void getCurrentTime(final int reactTag, final Promise promise) {
  try {
    UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(nvhm -> {
      YouTubeView youTubeView = (YouTubeView) nvhm.resolveView(reactTag);
      promise.resolve(youTubeView.getYouTubePlayerProps().getTracker().getCurrentSecond());
    });
  } catch (Exception e) {
    promise.reject("getCurrentTime", e);
  }
}
 
Example 18
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 4 votes vote down vote up
@ReactMethod
public void loadPlaylistItem(final int reactTag, final ReadableMap playlistItem) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute (NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playlistItem != null && playerView != null && playerView.mPlayer != null) {
          if (playlistItem.hasKey("file")) {
            String newFile = playlistItem.getString("file");

            PlaylistItem newPlayListItem = new PlaylistItem();

            newPlayListItem.setFile(newFile);

            if (playlistItem.hasKey("playerStyle")) {
              setCustomStyle(playerView.mPlayer, playlistItem.getString("playerStyle"));
            }

            if (playlistItem.hasKey("title")) {
              newPlayListItem.setTitle(playlistItem.getString("title"));
            }

            if (playlistItem.hasKey("desc")) {
              newPlayListItem.setDescription(playlistItem.getString("desc"));
            }

            if (playlistItem.hasKey("image")) {
              newPlayListItem.setImage(playlistItem.getString("image"));
            }

            if (playlistItem.hasKey("mediaId")) {
              newPlayListItem.setMediaId(playlistItem.getString("mediaId"));
            }

            boolean autostart = true;
            boolean controls = true;

            if (playlistItem.hasKey("autostart")) {
              autostart = playlistItem.getBoolean("autostart");
            }

            if (playlistItem.hasKey("controls")) {
              controls = playlistItem.getBoolean("controls");
            }

            playerView.mPlayer.getConfig().setAutostart(autostart);
            playerView.mPlayer.getConfig().setControls(controls);
            playerView.mPlayer.setControls(controls);

            playerView.mPlayer.load(newPlayListItem);

            if (autostart) {
              playerView.mPlayer.play();
            }
          }
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}
 
Example 19
Source File: RNJWPlayerModule.java    From react-native-jw-media-player with MIT License 4 votes vote down vote up
@ReactMethod
public void loadPlaylist(final int reactTag, final ReadableArray playlist) {
  try {
    UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
    uiManager.addUIBlock(new UIBlock() {
      public void execute(NativeViewHierarchyManager nvhm) {
        RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

        if (playlist != null && playlist.size() > 0 && playerView != null && playerView.mPlayer != null) {

          List<PlaylistItem> mPlayList = new ArrayList<>();
          ReadableMap playlistItem;
          String file = "";
          String image = "";
          String title = "";
          String desc = "";
          String mediaId = "";
          Boolean autostart = true;
          Boolean controls = true;

          int j = 0;
          while (playlist.size() > j) {
            playlistItem = playlist.getMap(j);

            if (playlistItem != null) {

              if (playlistItem.hasKey("file")) {
                file = playlistItem.getString("file");
              }

              if (playlistItem.hasKey("title")) {
                title = playlistItem.getString("title");
              }

              if (playlistItem.hasKey("desc")) {
                desc = playlistItem.getString("desc");
              }

              if (playlistItem.hasKey("image")) {
                image = playlistItem.getString("image");
              }

              if (playlistItem.hasKey("mediaId")) {
                mediaId = playlistItem.getString("mediaId");
              }

              if (playlistItem.hasKey("autostart")) {
                autostart = playlistItem.getBoolean("autostart");
              }

              if (playlistItem.hasKey("controls")) {
                controls = playlistItem.getBoolean("controls");
              }

              PlaylistItem newPlayListItem = new PlaylistItem.Builder()
                      .file(file)
                      .title(title)
                      .description(desc)
                      .image(image)
                      .mediaId(mediaId)
                      .build();

              mPlayList.add(newPlayListItem);
            }

            j++;
          }

          if (playlist.getMap(0).hasKey("playerStyle")) {
            setCustomStyle(playerView.mPlayer, playlist.getMap(0).getString("playerStyle"));
          }

          playerView.mPlayer.getConfig().setAutostart(autostart);
          playerView.mPlayer.getConfig().setControls(controls);
          playerView.mPlayer.setControls(controls);
          playerView.mPlayer.load(mPlayList);

          if (autostart) {
            playerView.mPlayer.play();
          }
        }
      }
    });
  } catch (IllegalViewOperationException e) {
    throw e;
  }
}