feat:add nativeChannel to let js call native view's method

This commit is contained in:
pengfei.zhou
2019-11-18 10:14:33 +08:00
parent ae5287fd7e
commit 8c83c3d13e
4 changed files with 62 additions and 3 deletions

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { LayoutConfig, Group, Property, IView } from "./view";
import { Group, Property, IView } from "./view";
import { Gravity } from "../util/gravity";
export interface IStack extends IView {
@@ -22,8 +22,6 @@ export interface IStack extends IView {
export class Stack extends Group implements IStack {
}
export class Root extends Stack {
}

View File

@@ -255,6 +255,24 @@ export abstract class View implements Modeling, IView {
in(group: Group) {
group.addChild(this)
}
nativeChannel(context: any, name: string) {
let thisView: View | undefined = this
return function (...args: any) {
const func = context.shader.command
const viewIds = []
while (thisView != undefined) {
viewIds.push(thisView.viewId)
thisView = thisView.superview
}
const params = {
viewIds: viewIds.reverse(),
name,
args,
}
return Reflect.apply(func, undefined, [params]) as Promise<any>
}
}
}
export abstract class Superview extends View {