Skip to content

Commit

Permalink
iOS Swift Conversion (#2527)
Browse files Browse the repository at this point in the history
Converts iOS implementation from Objective-c to Swift

# During the conversion process some updates to the code structure were also made
- Modularize codebase from single file to smaller focused files
- Untangled large nested IF statements
- Added more null checks, since Swift is more strict with null pointers
- Added property to allow for decoding of local video sources with self contained key for offline playback
- Updates example apps to test react-native 0.63.4 and uses auto native dependency imports for android and ios
  • Loading branch information
nickfujita committed May 19, 2022
1 parent d681e55 commit 68b9db4
Show file tree
Hide file tree
Showing 138 changed files with 8,856 additions and 7,576 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ DerivedData
*.ipa
*.xcuserstate
project.xcworkspace
Pods

# Android/IJ
#
Expand All @@ -29,6 +30,9 @@ project.xcworkspace
.gradle
local.properties
*.hprof
.project
.settings
.classpath

# node.js
#
Expand All @@ -46,3 +50,7 @@ buck-out/
\.buckd/
android/app/libs
android/keystores/debug.keystore

# windows
Deploy.binlog
msbuild.binlog
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
- (Breaking) Bump shaka-player to 3.3.2 [#2587](https://github.com/react-native-video/react-native-video/pull/2587)
- Improve basic player example on android [#2662](https://github.com/react-native-video/react-native-video/pull/2662)
- Ensure we always use `hideShutterView` before showing the `shutterView` on Android [#2609](https://github.com/react-native-video/react-native-video/pull/2609)
- Convert iOS implementation to Swift [#2527](https://github.com/react-native-video/react-native-video/pull/2527)
- Add iOS support for decoding offline sources [#2527](https://github.com/react-native-video/react-native-video/pull/2527)
- Update basic example applications (React Native 0.63.4) [#2527](https://github.com/react-native-video/react-native-video/pull/2527)

### Version 5.2.0

Expand Down Expand Up @@ -223,4 +226,4 @@
- Add cookie support for ExoPlayer [#922](https://github.com/react-native-community/react-native-video/pull/922)
- Remove ExoPlayer onMetadata that wasn't being used [#1040](https://github.com/react-native-community/react-native-video/pull/1040)
- Fix bug where setting the progress interval on iOS didn't work [#800](https://github.com/react-native-community/react-native-video/pull/800)
- Support setting the poster resize mode [#595](https://github.com/react-native-community/react-native-video/pull/595)
- Support setting the poster resize mode [#595](https://github.com/react-native-community/react-native-video/pull/595)
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Version 3.0 features a number of changes to existing behavior. See [Updating](#u
* [Android](#android-installation)
* [Windows](#windows-installation)
* [react-native-dom](#react-native-dom-installation)
* [Examples](#examples)
* [iOS](#ios-example)
* [Android](#android-example)
* [Windows](#windows-example)
* [Usage](#usage)
* [iOS App Transport Security](#ios-app-transport-security)
* [Audio Mixing](#audio-mixing)
Expand Down Expand Up @@ -69,6 +73,12 @@ Run `npx pod-install`. Linking is not required in React Native 0.60 and above.

Run `react-native link react-native-video` to link the react-native-video library.

#### Enable Static Linking for dependencies in your ios project Podfile

Add `use_frameworks! :linkage => :static` just under `platform :ios` in your ios project Podfile.

[See the example ios project for reference](examples/basic/ios/Podfile#L5)

#### Using CocoaPods (required to enable caching)

Setup your Podfile like it is described in the [react-native documentation](https://facebook.github.io/react-native/docs/integration-with-existing-apps#configuring-cocoapods-dependencies).
Expand Down Expand Up @@ -166,6 +176,11 @@ android.enableJetifier=true

#### **MainApplication.java**

If using com.facebook.react.PackageList to auto import native dependencies, there are no updates required here. Please see the android example project for more details.
/examples/basic/android/app/src/main/java/com/videoplayer/MainApplication.java

##### For manual linking

On top, where imports are:

```java
Expand Down Expand Up @@ -257,6 +272,25 @@ const ReactNativeDomOptions = {
```
</details>

## Examples

Run `yarn xbasic install` before running any of the examples.

### iOS Example
```
yarn xbasic ios
```

### Android Example
```
yarn xbasic android
```

### Windows Example
```
yarn xbasic windows
```

## Usage

```javascript
Expand Down Expand Up @@ -926,6 +960,18 @@ Adjust the volume.

Platforms: all

#### localSourceEncryptionKeyScheme
Set the url scheme for stream encryption key for local assets

Type: String

Example:
```
localSourceEncryptionKeyScheme="my-offline-key"
```

Platforms: iOS


### Event props

Expand Down Expand Up @@ -1404,6 +1450,16 @@ To enable audio to play in background on iOS the audio session needs to be set t

## Updating

### Version 6.0.0

#### iOS

In your project Podfile add support for static dependency linking. This is required to support the new Promises subdependency in the iOS swift conversion.

Add `use_frameworks! :linkage => :static` just under `platform :ios` in your ios project Podfile.

[See the example ios project for reference](examples/basic/ios/Podfile#L5)

### Version 5.0.0

Probably you want to update your gradle version:
Expand Down
1 change: 1 addition & 0 deletions Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ Video.propTypes = {
certificateUrl: PropTypes.string,
getLicense: PropTypes.func,
}),
localSourceEncryptionKeyScheme: PropTypes.string,
minLoadRetryCount: PropTypes.number,
maxBitRate: PropTypes.number,
resizeMode: PropTypes.string,
Expand Down
6 changes: 0 additions & 6 deletions examples/basic/.buckconfig

This file was deleted.

58 changes: 0 additions & 58 deletions examples/basic/.flowconfig

This file was deleted.

1 change: 0 additions & 1 deletion examples/basic/.gitattributes

This file was deleted.

55 changes: 0 additions & 55 deletions examples/basic/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion examples/basic/.watchmanconfig

This file was deleted.

14 changes: 14 additions & 0 deletions examples/basic/__tests__/App-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @format
*/

import 'react-native';
import React from 'react';
import VideoPlayer from '../src/VideoPlayer';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

it('renders correctly', () => {
renderer.create(<VideoPlayer />);
});
67 changes: 28 additions & 39 deletions examples/basic/android/app/BUCK
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import re

# To learn about Buck see [Docs](https://buckbuild.com/).
# To run your application with Buck:
# - install Buck
Expand All @@ -10,57 +8,48 @@ import re
# - `buck install -r android/app` - compile, install and run application
#

load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")

lib_deps = []
for jarfile in glob(['libs/*.jar']):
name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile)
lib_deps.append(':' + name)
prebuilt_jar(
name = name,
binary_jar = jarfile,
)

for aarfile in glob(['libs/*.aar']):
name = 'aars__' + re.sub(r'^.*/([^/]+)\.aar$', r'\1', aarfile)
lib_deps.append(':' + name)
android_prebuilt_aar(
name = name,
aar = aarfile,
)
create_aar_targets(glob(["libs/*.aar"]))

create_jar_targets(glob(["libs/*.jar"]))

android_library(
name = 'all-libs',
exported_deps = lib_deps
name = "all-libs",
exported_deps = lib_deps,
)

android_library(
name = 'app-code',
srcs = glob([
'src/main/java/**/*.java',
]),
deps = [
':all-libs',
':build_config',
':res',
],
name = "app-code",
srcs = glob([
"src/main/java/**/*.java",
]),
deps = [
":all-libs",
":build_config",
":res",
],
)

android_build_config(
name = 'build_config',
package = 'com.videoplayer',
name = "build_config",
package = "com.videoplayer",
)

android_resource(
name = 'res',
res = 'src/main/res',
package = 'com.videoplayer',
name = "res",
package = "com.videoplayer",
res = "src/main/res",
)

android_binary(
name = 'app',
package_type = 'debug',
manifest = 'src/main/AndroidManifest.xml',
keystore = '//android/keystores:debug',
deps = [
':app-code',
],
name = "app",
keystore = "//android/keystores:debug",
manifest = "src/main/AndroidManifest.xml",
package_type = "debug",
deps = [
":app-code",
],
)
Loading

0 comments on commit 68b9db4

Please sign in to comment.