Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NativeScript 6, and playback inside modals on Android #47

Merged
merged 1 commit into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo-vue/app/App_Resources/Android/app.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android {
defaultConfig {
generatedDensities = []
applicationId = "__PACKAGE__"
applicationId = "com.github.triniwiz.youtubeplayer"
}
aaptOptions {
additionalParameters "--no-version-vectors"
Expand Down
18 changes: 10 additions & 8 deletions demo-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
"nativescript": {
"id": "com.github.triniwiz.youtubeplayer",
"tns-ios": {
"version": "5.0.0"
"version": "6.0.1"
},
"tns-android": {
"version": "5.0.0"
"version": "6.0.0"
}
},
"dependencies": {
"nativescript-theme-core": "^1.0.4",
"nativescript-vue": "~2.0.2",
"nativescript-theme-core": "~1.0.6",
"nativescript-vue": "~2.4.0",
"nativescript-youtubeplayer": "file:../src",
"tns-core-modules": "~5.1.2"
"tns-core-modules": "~6.0.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand All @@ -30,15 +30,17 @@
"copy-webpack-plugin": "^4.5.2",
"css-loader": "^1.0.0",
"lazy": "1.0.11",
"nativescript-dev-webpack": "next",
"nativescript-dev-webpack": "1.0.1",
"nativescript-vue-template-compiler": "^2.0.0",
"nativescript-worker-loader": "~0.9.0",
"nativescript-worker-loader": "~0.9.1",
"node-sass": "^4.9.2",
"sass-loader": "^7.1.0",
"terser-webpack-plugin": "^1.1.0",
"tns-platform-declarations": "~6.0.0",
"typescript": "~3.4.5",
"vue-loader": "^15.2.6",
"webpack": "^4.16.4",
"webpack-bundle-analyzer": "~2.13.1",
"webpack-cli": "^3.1.0"
"webpack-cli": "rm ^3.1.0"
}
}
4 changes: 2 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"demo.ng.android": "npm i && npm run tsc && cd ../demo-ng && tns run android --syncAllFiles",
"demo.ng.webpack.android": "npm i && npm run tsc && cd ../demo-ng && npm run start-android-bundle",
"demo.ng.webpack.ios": "npm i && npm run tsc && cd ../demo-ng && npm run start-ios-bundle",
"demo-vue.ios": "npm run tsc && cd ../demo-vue && tns run ios --bundle --syncAllFiles",
"demo-vue.android": "npm run tsc && cd ../demo-vue && tns run android --bundle --syncAllFiles",
"demo-vue.ios": "npm run tsc && cd ../demo-vue && tns run ios --bundle",
"demo-vue.android": "npm run tsc && cd ../demo-vue && tns run android --bundle",
"clean": "rm -rf node_modules && cd ../demo && rm -rf hooks node_modules platforms && cd ../src && npm run plugin.link",
"ngc": "ngc --project tsconfig.aot.json",
"prepublish": "npm run ngc",
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/android/include.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ repositories {
}

android {

}

dependencies {
compile 'com.github.tommus:youtube-android-player-api:1.2.2'
compile 'com.github.tommus:youtube-android-player-api:1.2.3'
}
10 changes: 7 additions & 3 deletions src/youtubeplayer.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ export class YoutubePlayer extends YoutubePlayerBase {
this._layoutId = android.view.View.generateViewId();
const nativeView = new android.widget.LinearLayout(this._context);
nativeView.setId(this._layoutId);
const manager = app.android.foregroundActivity.getFragmentManager();
// this uses a private API, but it's the best (or rather: easiest) way I could find to support showing the fragment in modals
const manager: android.support.v4.app.FragmentManager = (<any>this)._getFragmentManager();
const fragment = manager.findFragmentByTag(FRAGMENT_TAG);
if (!fragment) {
this._fragment = com.google.android.youtube.player.YouTubePlayerFragment.newInstance();
this._fragment = com.google.android.youtube.player.YouTubePlayerSupportFragment.newInstance();
manager
.beginTransaction()
.replace(this._layoutId, this._fragment, FRAGMENT_TAG)
Expand Down Expand Up @@ -236,7 +237,10 @@ export class YoutubePlayer extends YoutubePlayerBase {
if (this._fragment) {
const activity = app.android.foregroundActivity;
if (activity && !activity.isFinishing()) {
activity.getFragmentManager().beginTransaction().remove(this._fragment).commit();
(<android.support.v4.app.FragmentManager>(<any>this)._getFragmentManager())
.beginTransaction()
.remove(this._fragment)
.commit();
this._fragment = null;
}
}
Expand Down