success to call promise
This commit is contained in:
parent
eb1c076dfb
commit
410ee99414
@ -5,8 +5,10 @@ import android.widget.Toast;
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
import com.github.penfeizhou.doric.extension.bridge.DoricMethod;
|
||||
import com.github.penfeizhou.doric.extension.bridge.DoricPlugin;
|
||||
import com.github.penfeizhou.doric.extension.bridge.DoricPromise;
|
||||
import com.github.penfeizhou.doric.plugin.DoricJavaPlugin;
|
||||
import com.github.penfeizhou.doric.utils.ThreadMode;
|
||||
import com.github.pengfeizhou.jscore.JavaValue;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doricdemo
|
||||
@ -25,7 +27,12 @@ public class DemoPlugin extends DoricJavaPlugin {
|
||||
}
|
||||
|
||||
@DoricMethod(thread = ThreadMode.UI)
|
||||
public void testPromise() {
|
||||
public void testPromise(boolean b, DoricPromise doricPromise) {
|
||||
if (b) {
|
||||
doricPromise.resolve(new JavaValue("resolved by me"));
|
||||
} else {
|
||||
doricPromise.reject(new JavaValue("rejected by me"));
|
||||
}
|
||||
Toast.makeText(getDoricContext().getContext(), "test", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,15 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
buildJSBundle.exec()
|
||||
}
|
||||
|
||||
task buildJSBundle(type: Exec) {
|
||||
workingDir project.rootDir.getParent() + "/js-framework"
|
||||
commandLine 'npm', 'run', 'build'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
@ -35,5 +44,5 @@ dependencies {
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
implementation 'com.github.pengfeizhou:jsc4a:0.1.0'
|
||||
api 'com.github.pengfeizhou:jsc4a:0.1.0'
|
||||
}
|
||||
|
@ -19,18 +19,22 @@ public class DoricPromise {
|
||||
}
|
||||
|
||||
public void resolve(JavaValue... javaValue) {
|
||||
Object[] params = new Object[javaValue.length + 2];
|
||||
params[0] = context.getContextId();
|
||||
params[1] = callbackId;
|
||||
System.arraycopy(javaValue, 0, params, 2, javaValue.length);
|
||||
context.getDriver().invokeDoricMethod(
|
||||
DoricConstant.DORIC_BRIDGE_RESOLVE,
|
||||
context.getContextId(),
|
||||
callbackId,
|
||||
javaValue);
|
||||
params);
|
||||
}
|
||||
|
||||
public void reject(JavaValue... javaValue) {
|
||||
Object[] params = new Object[javaValue.length + 2];
|
||||
params[0] = context.getContextId();
|
||||
params[1] = callbackId;
|
||||
System.arraycopy(javaValue, 0, params, 2, javaValue.length);
|
||||
context.getDriver().invokeDoricMethod(
|
||||
DoricConstant.DORIC_BRIDGE_REJECT,
|
||||
context.getContextId(),
|
||||
callbackId,
|
||||
javaValue);
|
||||
params);
|
||||
}
|
||||
}
|
||||
|
@ -9,26 +9,26 @@ v.bgColor = Color.parse('#00ff00')
|
||||
v.config = {
|
||||
alignment: Alignment.start
|
||||
}
|
||||
console.log(v.toModel())
|
||||
// console.log(v.toModel())
|
||||
|
||||
const layout = new VLayout
|
||||
layout.space = 10
|
||||
console.log(layout.viewId)
|
||||
console.log(layout.toModel())
|
||||
log('console', Object.getOwnPropertyNames(console))
|
||||
// log('console', Object.getOwnPropertyNames(console))
|
||||
|
||||
setTimeout(() => {
|
||||
log('exec setTimeout')
|
||||
// context.callNative("modal", "toast", "Hello,Doric!")
|
||||
}, 1000)
|
||||
const timerId = setInterval(() => {
|
||||
log('exec setInterval')
|
||||
}, 1000)
|
||||
// setTimeout(() => {
|
||||
// log('exec setTimeout')
|
||||
// // context.callNative("modal", "toast", "Hello,Doric!")
|
||||
// }, 1000)
|
||||
// const timerId = setInterval(() => {
|
||||
// log('exec setInterval')
|
||||
// }, 1000)
|
||||
|
||||
setTimeout(() => {
|
||||
log('exec cancelTimer')
|
||||
clearInterval(timerId)
|
||||
}, 5000)
|
||||
// setTimeout(() => {
|
||||
// log('exec cancelTimer')
|
||||
// clearInterval(timerId)
|
||||
// }, 5000)
|
||||
|
||||
@Link(context)
|
||||
export class MyPage extends Panel {
|
||||
@ -36,11 +36,18 @@ export class MyPage extends Panel {
|
||||
return layout
|
||||
}
|
||||
log() {
|
||||
log("Hello.HEGO")
|
||||
logw("Hello.HEGO")
|
||||
loge("Hello.HEGO")
|
||||
setTimeout(() => {
|
||||
context.bridge.demo_test()
|
||||
}, 1000)
|
||||
// log("Hello.HEGO")
|
||||
// logw("Hello.HEGO")
|
||||
// loge("Hello.HEGO")
|
||||
context.bridge.demo_testPromise(true).then((r) => {
|
||||
log('resolve', r)
|
||||
}, (e) => {
|
||||
log('reject', e)
|
||||
})
|
||||
context.bridge.demo_testPromise(false).then((r) => {
|
||||
log('resolve', r)
|
||||
}, (e) => {
|
||||
log('reject', e)
|
||||
})
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ export function jsCallResolve(contextId: string, callbackId: string, args?: any)
|
||||
for (let i = 2; i < arguments.length; i++) {
|
||||
argumentsList.push(arguments[i])
|
||||
}
|
||||
Reflect.apply(callback.resolve, context, args)
|
||||
Reflect.apply(callback.resolve, context, argumentsList)
|
||||
}
|
||||
|
||||
export function jsCallReject(contextId: string, callbackId: string, args?: any) {
|
||||
@ -64,7 +64,7 @@ export function jsCallReject(contextId: string, callbackId: string, args?: any)
|
||||
for (let i = 2; i < arguments.length; i++) {
|
||||
argumentsList.push(arguments[i])
|
||||
}
|
||||
Reflect.apply(callback.reject, context, args)
|
||||
Reflect.apply(callback.reject, context, argumentsList)
|
||||
}
|
||||
|
||||
export class Context {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { } from './../runtime/global';
|
||||
import { View, Stack, Group } from "./view";
|
||||
import { log } from 'util';
|
||||
import { loge } from '../util/log';
|
||||
import { loge, log } from '../util/log';
|
||||
|
||||
export function Link(context: any) {
|
||||
return <T extends { new(...args: any[]): {} }>(constructor: T) => {
|
||||
|
Reference in New Issue
Block a user