Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,28 @@
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.MapBuilder;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

public class TransparentVideoViewManager extends SimpleViewManager<LinearLayout> {

private static List<LinearLayout> sInstances = new ArrayList<>();
private static Map<LinearLayout, Boolean> sLoopSettings = new HashMap<>();

public static final String REACT_CLASS = "TransparentVideoView";
private static final String TAG = "TransparentVideoViewManager";
Expand All @@ -49,18 +57,42 @@ public LinearLayout createViewInstance(ThemedReactContext reactContext) {

public static void destroyView(LinearLayout view) {
sInstances.remove(view);
sLoopSettings.remove(view);
}

@Override
@Nullable
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
return MapBuilder.<String, Object>builder()
.put("onLoad", MapBuilder.of("registrationName", "onLoad"))
.build();
}

@ReactProp(name = "src")
public void setSrc(LinearLayout view, ReadableMap src) {
AlphaMovieView alphaMovieView = (AlphaMovieView)view.getChildAt(0);

if (alphaMovieView == null) {
alphaMovieView = new AlphaMovieView(reactContext, null);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
lp.gravity = Gravity.CENTER;
alphaMovieView.setLayoutParams(lp);
alphaMovieView.setAutoPlayAfterResume(true);
view.addView(alphaMovieView);

// Apply saved loop setting
Boolean loopSetting = sLoopSettings.get(view);
alphaMovieView.setLooping(loopSetting != null ? loopSetting : true);

// Send onLoad event when video starts
final int viewId = view.getId();
alphaMovieView.setOnVideoStartedListener(new AlphaMovieView.OnVideoStartedListener() {
@Override
public void onVideoStarted() {
WritableMap event = Arguments.createMap();
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(viewId, "onLoad", event);
}
});
}
alphaMovieView.setPacked(true);
String file = src.getString("uri").toLowerCase();
Expand All @@ -76,4 +108,14 @@ public void setSrc(LinearLayout view, ReadableMap src) {
alphaMovieView.setVideoByUrl(file);
}
}

@ReactProp(name = "loop", defaultBoolean = true)
public void setLoop(LinearLayout view, boolean loop) {
sLoopSettings.put(view, loop);

AlphaMovieView alphaMovieView = (AlphaMovieView)view.getChildAt(0);
if (alphaMovieView != null) {
alphaMovieView.setLooping(loop);
}
}
}
23 changes: 1 addition & 22 deletions react-native-transparent-video.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

Pod::Spec.new do |s|
s.name = "react-native-transparent-video"
Expand All @@ -11,30 +10,10 @@ Pod::Spec.new do |s|
s.license = package["license"]
s.authors = package["author"]

s.platforms = { :ios => "11.0" }
s.platforms = { :ios => "13.4" }
s.source = { :git => "https://github.com/status-im/react-native-transparent-video.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm,swift}"

s.dependency "React-Core"

# s.ios.user_target_xcconfig = {
# 'OTHER_LDFLAGS' => '-fcikernel',
# }

# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
s.dependency "React-RCTFabric"
s.dependency "React-Codegen"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
end