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.DoricContext;
|
||||||
import com.github.penfeizhou.doric.extension.bridge.DoricMethod;
|
import com.github.penfeizhou.doric.extension.bridge.DoricMethod;
|
||||||
import com.github.penfeizhou.doric.extension.bridge.DoricPlugin;
|
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.plugin.DoricJavaPlugin;
|
||||||
import com.github.penfeizhou.doric.utils.ThreadMode;
|
import com.github.penfeizhou.doric.utils.ThreadMode;
|
||||||
|
import com.github.pengfeizhou.jscore.JavaValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: com.github.penfeizhou.doricdemo
|
* @Description: com.github.penfeizhou.doricdemo
|
||||||
@ -25,7 +27,12 @@ public class DemoPlugin extends DoricJavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DoricMethod(thread = ThreadMode.UI)
|
@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();
|
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 {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
|
|
||||||
@ -35,5 +44,5 @@ dependencies {
|
|||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.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) {
|
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(
|
context.getDriver().invokeDoricMethod(
|
||||||
DoricConstant.DORIC_BRIDGE_RESOLVE,
|
DoricConstant.DORIC_BRIDGE_RESOLVE,
|
||||||
context.getContextId(),
|
params);
|
||||||
callbackId,
|
|
||||||
javaValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reject(JavaValue... javaValue) {
|
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(
|
context.getDriver().invokeDoricMethod(
|
||||||
DoricConstant.DORIC_BRIDGE_REJECT,
|
DoricConstant.DORIC_BRIDGE_REJECT,
|
||||||
context.getContextId(),
|
params);
|
||||||
callbackId,
|
|
||||||
javaValue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,26 +9,26 @@ v.bgColor = Color.parse('#00ff00')
|
|||||||
v.config = {
|
v.config = {
|
||||||
alignment: Alignment.start
|
alignment: Alignment.start
|
||||||
}
|
}
|
||||||
console.log(v.toModel())
|
// console.log(v.toModel())
|
||||||
|
|
||||||
const layout = new VLayout
|
const layout = new VLayout
|
||||||
layout.space = 10
|
layout.space = 10
|
||||||
console.log(layout.viewId)
|
console.log(layout.viewId)
|
||||||
console.log(layout.toModel())
|
console.log(layout.toModel())
|
||||||
log('console', Object.getOwnPropertyNames(console))
|
// log('console', Object.getOwnPropertyNames(console))
|
||||||
|
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
log('exec setTimeout')
|
// log('exec setTimeout')
|
||||||
// context.callNative("modal", "toast", "Hello,Doric!")
|
// // context.callNative("modal", "toast", "Hello,Doric!")
|
||||||
}, 1000)
|
// }, 1000)
|
||||||
const timerId = setInterval(() => {
|
// const timerId = setInterval(() => {
|
||||||
log('exec setInterval')
|
// log('exec setInterval')
|
||||||
}, 1000)
|
// }, 1000)
|
||||||
|
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
log('exec cancelTimer')
|
// log('exec cancelTimer')
|
||||||
clearInterval(timerId)
|
// clearInterval(timerId)
|
||||||
}, 5000)
|
// }, 5000)
|
||||||
|
|
||||||
@Link(context)
|
@Link(context)
|
||||||
export class MyPage extends Panel {
|
export class MyPage extends Panel {
|
||||||
@ -36,11 +36,18 @@ export class MyPage extends Panel {
|
|||||||
return layout
|
return layout
|
||||||
}
|
}
|
||||||
log() {
|
log() {
|
||||||
log("Hello.HEGO")
|
// log("Hello.HEGO")
|
||||||
logw("Hello.HEGO")
|
// logw("Hello.HEGO")
|
||||||
loge("Hello.HEGO")
|
// loge("Hello.HEGO")
|
||||||
setTimeout(() => {
|
context.bridge.demo_testPromise(true).then((r) => {
|
||||||
context.bridge.demo_test()
|
log('resolve', r)
|
||||||
}, 1000)
|
}, (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++) {
|
for (let i = 2; i < arguments.length; i++) {
|
||||||
argumentsList.push(arguments[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) {
|
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++) {
|
for (let i = 2; i < arguments.length; i++) {
|
||||||
argumentsList.push(arguments[i])
|
argumentsList.push(arguments[i])
|
||||||
}
|
}
|
||||||
Reflect.apply(callback.reject, context, args)
|
Reflect.apply(callback.reject, context, argumentsList)
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Context {
|
export class Context {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { } from './../runtime/global';
|
import { } from './../runtime/global';
|
||||||
import { View, Stack, Group } from "./view";
|
import { View, Stack, Group } from "./view";
|
||||||
import { log } from 'util';
|
import { loge, log } from '../util/log';
|
||||||
import { loge } from '../util/log';
|
|
||||||
|
|
||||||
export function Link(context: any) {
|
export function Link(context: any) {
|
||||||
return <T extends { new(...args: any[]): {} }>(constructor: T) => {
|
return <T extends { new(...args: any[]): {} }>(constructor: T) => {
|
||||||
|
Reference in New Issue
Block a user