Skip to content

Commit

Permalink
Fix Web listener jeepCapPhotoViewerExit
Browse files Browse the repository at this point in the history
  • Loading branch information
jepiqueau committed Sep 16, 2023
1 parent 40ab00f commit 527f310
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 40 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 3.0.2 (2023-09-16)

## Bug fixes

- Fix Web listener `jeepCapPhotoViewerExit`not fired.

# 3.0.1 (2023-09-12)

### Chore
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ buildscript {
ext.kotlin_version = '1.8.20'
dependencies {
...
classpath 'com.android.tools.build:gradle:8.0.0'
classpath 'com.google.gms:google-services:4.3.15'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down Expand Up @@ -126,7 +128,7 @@ buildscript {
```
- in the `dependencies` block add
```
implementation "androidx.core:core-ktx:1.6.0"
implementation "androidx.core:core-ktx:1.10.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
```
Expand Down
12 changes: 6 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':capacitor-android')
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.core:core-ktx:1.9.0"
implementation "androidx.core:core-ktx:1.10.0"
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.recyclerview:recyclerview:1.3.1'
implementation 'com.github.bumptech.glide:glide:4.14.0'
kapt 'com.github.bumptech.glide:compiler:4.14.0'
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
implementation 'androidx.fragment:fragment-ktx:1.5.5'
implementation 'com.github.MikeOrtiz:TouchImageView:3.3'
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta02'
implementation 'androidx.fragment:fragment-ktx:1.6.1'
implementation 'com.github.MikeOrtiz:TouchImageView:3.5'
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
Expand Down
21 changes: 13 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@
}
},
"dependencies": {
"jeep-photoviewer": "^1.1.8"
"jeep-photoviewer": "^1.2.0"
}
}
50 changes: 26 additions & 24 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ export class PhotoViewerWeb extends WebPlugin implements PhotoViewerPlugin {
private _startFrom = 0;
private _container: any;
private _modeList: string[] = ['one', 'gallery', 'slider'];
private _photoViewer!: HTMLJeepPhotoviewerElement;

constructor() {
super();
document.addEventListener(
'jeepPhotoViewerResult',
this.jeepPhotoViewerResult,
false,
);
}

async echo(options: capEchoOptions): Promise<capEchoResult> {
return options;
}
async show(options: capShowOptions): Promise<capShowResult> {
return new Promise<capShowResult>((resolve, reject) => {
// return new Promise<capShowResult>( (resolve, reject) => {
jeepPhotoviewer(window);
if (Object.keys(options).includes('images')) {
this._imageList = options.images;
Expand All @@ -41,17 +51,16 @@ export class PhotoViewerWeb extends WebPlugin implements PhotoViewerPlugin {
const mStartFrom = options.startFrom;
this._startFrom = mStartFrom ?? 0;
}
const photoViewer: HTMLJeepPhotoviewerElement =
document.createElement('jeep-photoviewer');
photoViewer.imageList = this._imageList;
photoViewer.mode = this._mode;
this._photoViewer = document.createElement('jeep-photoviewer');
this._photoViewer.imageList = this._imageList;
this._photoViewer.mode = this._mode;
if (this._mode === 'one' || this._mode === 'slider') {
photoViewer.startFrom = this._startFrom;
this._photoViewer.startFrom = this._startFrom;
}
const optionsKeys: string[] = Object.keys(this._options);
let divid: string | undefined;
if (optionsKeys.length > 0) {
photoViewer.options = this._options;
this._photoViewer.options = this._options;
if (optionsKeys.includes('divid')) {
divid = this._options.divid;
} else {
Expand All @@ -68,25 +77,18 @@ export class PhotoViewerWeb extends WebPlugin implements PhotoViewerPlugin {
this._container.removeChild(isPVEl);
}

photoViewer.addEventListener(
'jeepPhotoViewerResult',
async (ev: any) => {
const res = ev.detail;
if (res === null) {
reject('Error: event does not include detail ');
} else {
this.notifyListeners('jeepCapPhotoViewerExit', res);
this._container.removeChild(photoViewer);
resolve(res);
}
},
false,
);
this._container.appendChild(this._photoViewer);
await customElements.whenDefined('jeep-photoviewer');

this._container.appendChild(photoViewer);
return Promise.resolve({result: true})
} else {
reject("Div id='photoviewer-container' not found");
return Promise.reject("Div id='photoviewer-container' not found");
}
});
}
private jeepPhotoViewerResult = (ev: any) => {
const res = ev.detail;
if(res !== null) {
this.notifyListeners('jeepCapPhotoViewerExit', res);
}
};
}

0 comments on commit 527f310

Please sign in to comment.