diff --git a/android/src/main/java/com/transparentvideo/TransparentVideoViewManager.java b/android/src/main/java/com/transparentvideo/TransparentVideoViewManager.java index 2f32623..1dd9dde 100644 --- a/android/src/main/java/com/transparentvideo/TransparentVideoViewManager.java +++ b/android/src/main/java/com/transparentvideo/TransparentVideoViewManager.java @@ -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 { private static List sInstances = new ArrayList<>(); + private static Map sLoopSettings = new HashMap<>(); public static final String REACT_CLASS = "TransparentVideoView"; private static final String TAG = "TransparentVideoViewManager"; @@ -49,11 +57,21 @@ public LinearLayout createViewInstance(ThemedReactContext reactContext) { public static void destroyView(LinearLayout view) { sInstances.remove(view); + sLoopSettings.remove(view); + } + + @Override + @Nullable + public Map getExportedCustomDirectEventTypeConstants() { + return MapBuilder.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); @@ -61,6 +79,20 @@ public void setSrc(LinearLayout view, ReadableMap src) { 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(); @@ -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); + } + } } diff --git a/react-native-transparent-video.podspec b/react-native-transparent-video.podspec index ff34054..0d8fa1f 100644 --- a/react-native-transparent-video.podspec +++ b/react-native-transparent-video.podspec @@ -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" @@ -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