2020-02-25 07:21:06 -07:00
|
|
|
#include "pch.h"
|
|
|
|
#include "ReactVideoViewManager.h"
|
|
|
|
#include "NativeModules.h"
|
|
|
|
#include "ReactVideoView.h"
|
|
|
|
|
|
|
|
namespace winrt::ReactNativeVideoCPP::implementation {
|
|
|
|
|
|
|
|
ReactVideoViewManager::ReactVideoViewManager() {}
|
|
|
|
|
|
|
|
// IViewManager
|
|
|
|
hstring ReactVideoViewManager::Name() noexcept {
|
|
|
|
return L"RCTVideo";
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameworkElement ReactVideoViewManager::CreateView() noexcept {
|
|
|
|
auto reactVideoView = winrt::ReactNativeVideoCPP::ReactVideoView(m_reactContext);
|
|
|
|
return reactVideoView;
|
|
|
|
}
|
|
|
|
|
|
|
|
// IViewManagerWithReactContext
|
|
|
|
IReactContext ReactVideoViewManager::ReactContext() noexcept {
|
|
|
|
return m_reactContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReactVideoViewManager::ReactContext(IReactContext reactContext) noexcept {
|
|
|
|
m_reactContext = reactContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// IViewManagerWithExportedViewConstants
|
|
|
|
winrt::Microsoft::ReactNative::ConstantProviderDelegate ReactVideoViewManager::ExportedViewConstants() noexcept {
|
|
|
|
return [](winrt::Microsoft::ReactNative::IJSValueWriter const &constantWriter) {
|
|
|
|
WriteProperty(constantWriter, L"ScaleNone", to_hstring(std::to_string((int)Stretch::None)));
|
|
|
|
WriteProperty(constantWriter, L"ScaleToFill", to_hstring(std::to_string((int)Stretch::UniformToFill)));
|
|
|
|
WriteProperty(constantWriter, L"ScaleAspectFit", to_hstring(std::to_string((int)Stretch::Uniform)));
|
|
|
|
WriteProperty(constantWriter, L"ScaleAspectFill", to_hstring(std::to_string((int)Stretch::Fill)));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// IViewManagerWithNativeProperties
|
|
|
|
IMapView<hstring, ViewManagerPropertyType> ReactVideoViewManager::NativeProps() noexcept {
|
|
|
|
auto nativeProps = winrt::single_threaded_map<hstring, ViewManagerPropertyType>();
|
|
|
|
nativeProps.Insert(L"src", ViewManagerPropertyType::Map);
|
|
|
|
nativeProps.Insert(L"resizeMode", ViewManagerPropertyType::String);
|
|
|
|
nativeProps.Insert(L"repeat", ViewManagerPropertyType::Boolean);
|
|
|
|
nativeProps.Insert(L"paused", ViewManagerPropertyType::Boolean);
|
|
|
|
nativeProps.Insert(L"muted", ViewManagerPropertyType::Boolean);
|
|
|
|
nativeProps.Insert(L"volume", ViewManagerPropertyType::Number);
|
|
|
|
nativeProps.Insert(L"seek", ViewManagerPropertyType::Number);
|
|
|
|
nativeProps.Insert(L"controls", ViewManagerPropertyType::Boolean);
|
|
|
|
nativeProps.Insert(L"fullscreen", ViewManagerPropertyType::Boolean);
|
|
|
|
nativeProps.Insert(L"progressUpdateInterval", ViewManagerPropertyType::Number);
|
2021-04-08 11:37:35 -06:00
|
|
|
nativeProps.Insert(L"rate", ViewManagerPropertyType::Number);
|
2020-02-25 07:21:06 -07:00
|
|
|
|
|
|
|
return nativeProps.GetView();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReactVideoViewManager::UpdateProperties(
|
|
|
|
FrameworkElement const &view,
|
|
|
|
IJSValueReader const &propertyMapReader) noexcept {
|
|
|
|
if (auto reactVideoView = view.try_as<winrt::ReactNativeVideoCPP::ReactVideoView>()) {
|
|
|
|
const JSValueObject &propertyMap = JSValue::ReadObjectFrom(propertyMapReader);
|
|
|
|
|
|
|
|
for (auto const &pair : propertyMap) {
|
|
|
|
auto const &propertyName = pair.first;
|
|
|
|
auto const &propertyValue = pair.second;
|
|
|
|
if (!propertyValue.IsNull()) {
|
|
|
|
if (propertyName == "src") {
|
2021-04-08 11:37:35 -06:00
|
|
|
auto const &srcMap = propertyValue.AsObject();
|
|
|
|
auto const &uri = srcMap.at("uri");
|
|
|
|
reactVideoView.Set_UriString(to_hstring(uri.AsString()));
|
2020-02-25 07:21:06 -07:00
|
|
|
} else if (propertyName == "resizeMode") {
|
2021-04-08 11:37:35 -06:00
|
|
|
reactVideoView.Stretch(static_cast<Stretch>(std::stoul(propertyValue.AsString())));
|
2020-02-25 07:21:06 -07:00
|
|
|
} else if (propertyName == "repeat") {
|
2021-04-08 11:37:35 -06:00
|
|
|
reactVideoView.Set_IsLoopingEnabled(propertyValue.AsBoolean());
|
2020-02-25 07:21:06 -07:00
|
|
|
} else if (propertyName == "paused") {
|
2021-04-08 11:37:35 -06:00
|
|
|
m_paused = propertyValue.AsBoolean();
|
|
|
|
reactVideoView.Set_Paused(m_paused);
|
2020-02-25 07:21:06 -07:00
|
|
|
} else if (propertyName == "muted") {
|
2021-04-08 11:37:35 -06:00
|
|
|
reactVideoView.Set_Muted(propertyValue.AsBoolean());
|
2020-02-25 07:21:06 -07:00
|
|
|
} else if (propertyName == "volume") {
|
2021-04-08 11:37:35 -06:00
|
|
|
reactVideoView.Set_Volume(propertyValue.AsDouble());
|
2020-02-25 07:21:06 -07:00
|
|
|
} else if (propertyName == "seek") {
|
2021-04-08 11:37:35 -06:00
|
|
|
reactVideoView.Set_Position(propertyValue.AsDouble());
|
2020-02-25 07:21:06 -07:00
|
|
|
} else if (propertyName == "controls") {
|
2021-04-08 11:37:35 -06:00
|
|
|
reactVideoView.Set_Controls(propertyValue.AsBoolean());
|
2020-02-25 07:21:06 -07:00
|
|
|
} else if (propertyName == "fullscreen") {
|
2021-04-08 11:37:35 -06:00
|
|
|
reactVideoView.Set_FullScreen(propertyValue.AsBoolean());
|
2020-02-25 07:21:06 -07:00
|
|
|
} else if (propertyName == "progressUpdateInterval") {
|
2021-04-08 11:37:35 -06:00
|
|
|
reactVideoView.Set_ProgressUpdateInterval(propertyValue.AsInt64());
|
|
|
|
} else if (propertyName == "rate") {
|
|
|
|
reactVideoView.Set_PlaybackRate(propertyValue.AsDouble());
|
2020-02-25 07:21:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reactVideoView.Set_AutoPlay(!m_paused); // auto play on pause false or not set.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// IViewManagerWithExportedEventTypeConstants
|
|
|
|
ConstantProviderDelegate ReactVideoViewManager::ExportedCustomBubblingEventTypeConstants() noexcept {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstantProviderDelegate ReactVideoViewManager::ExportedCustomDirectEventTypeConstants() noexcept {
|
|
|
|
return [](winrt::Microsoft::ReactNative::IJSValueWriter const &constantWriter) {
|
|
|
|
WriteCustomDirectEventTypeConstant(constantWriter, "Load");
|
|
|
|
WriteCustomDirectEventTypeConstant(constantWriter, "End");
|
|
|
|
WriteCustomDirectEventTypeConstant(constantWriter, "Seek");
|
|
|
|
WriteCustomDirectEventTypeConstant(constantWriter, "Progress");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace winrt::ReactNativeVideoCPP::implementation
|