fix: remove runtime warning by replacing UIManager.RCTVideo with UIManager.getViewManagerConfig('RCTVideo') (and ensuring backwards compat) (#1487)

* replaced UIManager.RCTVideo >  UIManager.getViewManagerConfig('RCTVideo')

* added requested changes

* updated changelog.md

* docs: adjust wording
This commit is contained in:
Nick 2019-02-18 16:47:20 +05:30 committed by Laurin Quast
parent d8a2a9e108
commit b448b30de6
3 changed files with 15 additions and 6 deletions

View File

@ -1,4 +1,4 @@
{ {
"extends": "airbnb", "extends": "airbnb",
"parser": "babel-eslint" "parser": "babel-eslint"
} }

View File

@ -1,7 +1,7 @@
## Changelog ## Changelog
### next ### next
* Fix runtime warning by replacing `UIManager.RCTVideo` with `UIManager.getViewManagerConfig('RCTVideo')` (and ensuring backwards compat) [#1487](https://github.com/react-native-community/react-native-video/pull/1487)
* Fix loading package resolved videos when using video-caching [#1438](https://github.com/react-native-community/react-native-video/pull/1438) * Fix loading package resolved videos when using video-caching [#1438](https://github.com/react-native-community/react-native-video/pull/1438)
* Fix "message sent to deallocated instance" crash on ios [#1482](https://github.com/react-native-community/react-native-video/pull/1482) * Fix "message sent to deallocated instance" crash on ios [#1482](https://github.com/react-native-community/react-native-video/pull/1482)

View File

@ -210,6 +210,13 @@ export default class Video extends Component {
} }
}; };
getViewManagerConfig = viewManagerName => {
if (!UIManager.getViewManagerConfig) {
return UIManager[viewManagerName];
}
return UIManager.getViewManagerConfig(viewManagerName);
};
render() { render() {
const resizeMode = this.props.resizeMode; const resizeMode = this.props.resizeMode;
const source = resolveAssetSource(this.props.source) || {}; const source = resolveAssetSource(this.props.source) || {};
@ -224,14 +231,16 @@ export default class Video extends Component {
const isAsset = !!(uri && uri.match(/^(assets-library|ipod-library|file|content|ms-appx|ms-appdata):/)); const isAsset = !!(uri && uri.match(/^(assets-library|ipod-library|file|content|ms-appx|ms-appdata):/));
let nativeResizeMode; let nativeResizeMode;
const RCTVideoInstance = this.getViewManagerConfig('RCTVideo');
if (resizeMode === VideoResizeMode.stretch) { if (resizeMode === VideoResizeMode.stretch) {
nativeResizeMode = NativeModules.UIManager.RCTVideo.Constants.ScaleToFill; nativeResizeMode = RCTVideoInstance.Constants.ScaleToFill;
} else if (resizeMode === VideoResizeMode.contain) { } else if (resizeMode === VideoResizeMode.contain) {
nativeResizeMode = NativeModules.UIManager.RCTVideo.Constants.ScaleAspectFit; nativeResizeMode = RCTVideoInstance.Constants.ScaleAspectFit;
} else if (resizeMode === VideoResizeMode.cover) { } else if (resizeMode === VideoResizeMode.cover) {
nativeResizeMode = NativeModules.UIManager.RCTVideo.Constants.ScaleAspectFill; nativeResizeMode = RCTVideoInstance.Constants.ScaleAspectFill;
} else { } else {
nativeResizeMode = NativeModules.UIManager.RCTVideo.Constants.ScaleNone; nativeResizeMode = RCTVideoInstance.Constants.ScaleNone;
} }
const nativeProps = Object.assign({}, this.props); const nativeProps = Object.assign({}, this.props);