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

feat: 优化JSBridge中类实例方法过多问题 #15760

Merged
merged 3 commits into from
May 28, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class Index extends React.Component {
dataType: 'json',
method: 'POST',
data: { name: 'Taro' },
timeout: 10000,
headers: {
'Content-Type': 'application/json',
},
Expand Down
236 changes: 20 additions & 216 deletions packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,228 +388,12 @@ export class NativeApi {
return options
}

// NativeAContextApi
// @ts-ignore
@(syncAndRelease)
createInnerAudioContext (): any {}

// @ts-ignore
@(syncAndRelease)
innerAudioStop (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
innerAudioPause (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
innerAudioPlay (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndNotRelease)
innerAudioOnPlay (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndNotRelease)
innerAudioOnStop (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndNotRelease)
innerAudioOnError (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndNotRelease)
innerAudioOnEnded (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
getAudioContextVolume (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
setAudioContextVolume (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
getAudioContextStartTime (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
setAudioContextStartTime (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
getAudioContextPlaybackRate (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
setAudioContextPlaybackRate (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
getAudioContextPaused (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
setAudioContextPaused (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
getAudioContextObeyMuteSwitch (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
setAudioContextObeyMuteSwitch (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
getAudioContextLoop (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
setAudioContextLoop (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
getAudioContextDuration (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
setAudioContextDuration (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
getAudioContextCurrentTime (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
setAudioContextCurrentTime (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
getAudioContextBuffered (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
setAudioContextBuffered (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
getAudioContextAutoplay (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
setAudioContextAutoplay (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
getAudioContextSrc (option: any, _: number) {
return option
}

// @ts-ignore
@(syncAndRelease)
setAudioContextSrc (option: any, _: number) {
return option
}

// NativeUploadFile
// @ts-ignore
@(asyncAndNotRelease)
uploadFile (options: any): any {
return options
}

// @ts-ignore
@(syncAndRelease)
downloadFile (options: any): any {
return options
}

// @ts-ignore
@(syncAndRelease)
abort (option: any, _: number): any {
return option
}

// @ts-ignore
@(syncAndRelease)
offHeadersReceived (option: any, _: number): any {
return option
}

// @ts-ignore
@(syncAndRelease)
offProgressUpdate (option: any, _: number): any {
return option
}

// @ts-ignore
@(asyncAndNotRelease)
onHeadersReceived (option: any, _: number): any {
return option
}

// @ts-ignore
@(asyncAndNotRelease)
onProgressUpdate (option: any, _: number): any {
return option
}

// NativeFileSystemManager
// @ts-ignore
@(syncAndRelease)
Expand Down Expand Up @@ -825,6 +609,26 @@ export class NativeApi {
clearStorage (option: any): any {
return option
}

@(syncAndRelease)
callInstance (option: any): any {
return option
}

@(syncAndRelease)
createInstance (option: any): any {
return option
}

@(syncAndRelease)
syncAndReleaseInstance (option: any): any {
return option
}

@(asyncAndNotRelease)
callInstanceAsync (option: any): any {
return option
}
}

export interface Status {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import native from '../NativeApi'

export class ClassInstanceManager {
private static INSTANCE: ClassInstanceManager
private classIdMap: Map<string, number[]>
constructor () {
this.classIdMap = new Map<string, number[]>()
}

public static getInstance (): ClassInstanceManager {
if (!ClassInstanceManager.INSTANCE) {
ClassInstanceManager.INSTANCE = new ClassInstanceManager()
}
return ClassInstanceManager.INSTANCE
}

createInstance (className: string, option?: any) {
const objectId: number = native.createInstance({ ...option, className: className })
if (!this.classIdMap.has(className)) {
this.classIdMap.set(className, [])
}
(this.classIdMap.get(className) as Array<number>).push(objectId)
return objectId
}

getInstanceValue (className: string, name: string, objectId: number): any {
return native.callInstance({
type: 'get',
className: className,
property: name,
objectId: objectId
})
}

setInstanceValue (option: any, className: string, name: string, objectId: number): any {
return native.callInstance({
option: option,
className: className,
type: 'set',
property: name,
objectId: objectId
})
}

setInstanceFunction (option: any, className: string, name: string, objectId: number): any {
return native.callInstance({
option: option,
className: className,
type: 'function',
property: name,
objectId: objectId
})
}

setInstanceFunctionAsync (option: any, className: string, name: string, objectId: number): any {
return native.callInstanceAsync({
option: option,
className: className,
type: 'function',
property: name,
objectId: objectId
})
}

destroyInstance (className: string, objectId: number) {
const instances = this.classIdMap.get(className)
if (instances) {
const index = instances.indexOf(objectId)
if (index !== -1) {
instances.splice(index, 1)
}
native.syncAndReleaseInstance({ className: className, option: this.classIdMap.get(className) })
}
}
}
Loading
Loading