Git Product home page Git Product logo

creator-native-bridge's Introduction

cocos-creator Native Caller

从javascript调用本地代码的辅助工具。

  • 无需关心什么类型签名、包名。调用android和oc的代码相同
  • 支持把js函数直接传入本地代码,处理完功能直接调用js回调

javascript

native.callClz("SomeClass", "FuncName", "your string", 2017, true, (str, number, bool) => {
    cc.log(str, number, bool)
})

objective-c

@interface SomeClass : NSObject 
+(void) FuncName : (NSString*) str
        arg1 : (NSNumber) number 
        arg2 : (BOOL) b
        arg3 : (NSString*) cbName {
            JS::call(cbName, @[@"your string", @2017, Yes]);
        }
@end

java

class SomeClass {
    static public void FuncName(String s, double d, boolean b, String cbName) {
        Js.call(cbName, "your string", 2017, true);
    }
}

使用方法

  • 拷贝Native.js 到你的creator项目中
  • 拷贝Js.mm & Js.h 到你的ios目录,并添加到xcode中
  • 拷贝Js.java 到安卓 org/cocos2dx/javascript 下

注意

  • 在ios端调用js时候,bool值必须使用 Yes 和 No
  • 在ios端 函数多个参数 必须写成arg1 arg2 ... arg10这样。
  • js回调函数在本地代码中用string类型接收
  • js回调调用一次之后就会被移除。
  • Android端代码都要放在 org/cocos2dx/javascript 包下
  • 代码比较少,有bug请自行修改,当然也可以给个Pr。

creator-native-bridge's People

Contributors

qcdong2016 avatar

Watchers

James Cloos avatar 浪 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.