Optimize code size for VideoPlayer and WebView. (#18231)

This commit is contained in:
James Chen
2025-01-23 10:49:57 +08:00
committed by GitHub
parent 33b4c658ab
commit 01040a3494
3 changed files with 36 additions and 32 deletions
+21 -19
View File
@@ -372,22 +372,24 @@ export class VideoPlayer extends Component {
}
protected syncSource (): void {
if (!this._impl) { return; }
const impl = this._impl;
if (!impl) { return; }
if (this._resourceType === ResourceType.REMOTE) {
this._impl.syncURL(this._remoteURL);
impl.syncURL(this._remoteURL);
} else {
this._impl.syncClip(this._clip);
impl.syncClip(this._clip);
}
this._cachedCurrentTime = 0;
this._impl.syncLoop(this._loop);
this._impl.syncVolume(this._volume);
this._impl.syncMute(this._mute);
this._impl.seekTo(this._cachedCurrentTime);
this._impl.syncPlaybackRate(this._playbackRate);
this._impl.syncStayOnBottom(this._stayOnBottom);
this._impl.syncKeepAspectRatio(this._keepAspectRatio);
this._impl.syncFullScreenOnAwake(this._fullScreenOnAwake);
impl.syncLoop(this._loop);
impl.syncVolume(this._volume);
impl.syncMute(this._mute);
impl.seekTo(this._cachedCurrentTime);
impl.syncPlaybackRate(this._playbackRate);
impl.syncStayOnBottom(this._stayOnBottom);
impl.syncKeepAspectRatio(this._keepAspectRatio);
impl.syncFullScreenOnAwake(this._fullScreenOnAwake);
}
public __preload (): void {
@@ -436,43 +438,43 @@ export class VideoPlayer extends Component {
}
}
public onMetaLoaded (): void {
private onMetaLoaded (): void {
ComponentEventHandler.emitEvents(this.videoPlayerEvent, this, VideoPlayerEventType.META_LOADED);
this.node.emit('meta-loaded', this);
}
public onReadyToPlay (): void {
private onReadyToPlay (): void {
if (this._playOnAwake && !this.isPlaying) { this.play(); }
ComponentEventHandler.emitEvents(this.videoPlayerEvent, this, VideoPlayerEventType.READY_TO_PLAY);
this.node.emit(VideoPlayerEventType.READY_TO_PLAY, this);
}
public onPlaying (): void {
private onPlaying (): void {
ComponentEventHandler.emitEvents(this.videoPlayerEvent, this, VideoPlayerEventType.PLAYING);
this.node.emit(VideoPlayerEventType.PLAYING, this);
}
public onPaused (): void {
private onPaused (): void {
ComponentEventHandler.emitEvents(this.videoPlayerEvent, this, VideoPlayerEventType.PAUSED);
this.node.emit(VideoPlayerEventType.PAUSED, this);
}
public onStopped (): void {
private onStopped (): void {
ComponentEventHandler.emitEvents(this.videoPlayerEvent, this, VideoPlayerEventType.STOPPED);
this.node.emit(VideoPlayerEventType.STOPPED, this);
}
public onCompleted (): void {
private onCompleted (): void {
ComponentEventHandler.emitEvents(this.videoPlayerEvent, this, VideoPlayerEventType.COMPLETED);
this.node.emit(VideoPlayerEventType.COMPLETED, this);
}
public onError (): void {
private onError (): void {
ComponentEventHandler.emitEvents(this.videoPlayerEvent, this, VideoPlayerEventType.ERROR);
this.node.emit(VideoPlayerEventType.ERROR, this);
}
public onClicked (): void {
private onClicked (): void {
ComponentEventHandler.emitEvents(this.videoPlayerEvent, this, VideoPlayerEventType.CLICKED);
this.node.emit(VideoPlayerEventType.CLICKED, this);
}
+12 -10
View File
@@ -72,21 +72,23 @@ export class WebViewImplWeb extends WebViewImpl {
const wrapper = ccdocument.createElement('div');
this._wrapper = wrapper;
wrapper.id = 'webview-wrapper';
wrapper.style['-webkit-overflow'] = 'auto';
wrapper.style['-webkit-overflow-scrolling'] = 'touch';
wrapper.style.position = 'absolute';
wrapper.style.bottom = '0px';
wrapper.style.left = '0px';
wrapper.style.transformOrigin = '0px 100% 0px';
wrapper.style['-webkit-transform-origin'] = '0px 100% 0px';
const wrapperStyle = wrapper.style;
wrapperStyle['-webkit-overflow'] = 'auto';
wrapperStyle['-webkit-overflow-scrolling'] = 'touch';
wrapperStyle.position = 'absolute';
wrapperStyle.bottom = '0px';
wrapperStyle.left = '0px';
wrapperStyle.transformOrigin = '0px 100% 0px';
wrapperStyle['-webkit-transform-origin'] = '0px 100% 0px';
game.container!.appendChild(wrapper);
const webview = ccdocument.createElement('iframe');
this._webview = webview;
const webviewStyle = webview.style;
webview.id = 'webview';
webview.style.border = 'none';
webview.style.width = '100%';
webview.style.height = '100%';
webviewStyle.border = 'none';
webviewStyle.width = '100%';
webviewStyle.height = '100%';
wrapper.appendChild(webview);
this._bindDomEvent();
}
+3 -3
View File
@@ -178,17 +178,17 @@ export class WebView extends Component {
this._impl.loadURL(this._url);
}
onLoading (): void {
private onLoading (): void {
ComponentEventHandler.emitEvents(this.webviewEvents, this, WebViewEventType.LOADING);
this.node.emit(WebViewEventType.LOADING, this);
}
onLoaded (): void {
private onLoaded (): void {
ComponentEventHandler.emitEvents(this.webviewEvents, this, WebViewEventType.LOADED);
this.node.emit(WebViewEventType.LOADED, this);
}
onError (...args: any[any]): void {
private onError (...args: any[any]): void {
ComponentEventHandler.emitEvents(this.webviewEvents, this, WebViewEventType.ERROR, args);
this.node.emit(WebViewEventType.ERROR, this, args);
}