Last active
January 3, 2019 13:04
-
-
Save panvourtsis/714155aa2325b7b3b35bdb91f53fe2d3 to your computer and use it in GitHub Desktop.
JSMeetup Native Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.JSMeetup; | |
import ... | |
class JSMeetupModule extends ReactContextBaseJavaModule { | |
private static String mPremium = ""; | |
public JSMeetupModule(ReactApplicationContext reactContext) { | |
super(reactContext); | |
... | |
} | |
@Override | |
public String getName() { | |
return "JSMeetup"; | |
} | |
@ReactMethod | |
public void setPremium(String premium) { | |
mPremium = premium; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JSMeetupPackage implements ReactPackage { | |
@Override | |
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { | |
List<NativeModule> modules = new ArrayList<>(); | |
modules.add(new JSMeetupModule(reactContext)); | |
return modules; | |
} | |
@Override | |
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | |
List<ViewManager> modules = new ArrayList<>(); | |
modules.add(new JSMeetupViewManager(reactContext)); | |
return modules; // if we have a view else return Collections.emptyList(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JSMeetupReactView extends Component { | |
setInputUrl(url) { | |
NativeModules.JSMeetup.setInputUrl(url); | |
} | |
blah() { | |
UIManager.dispatchViewManagerCommand( | |
findNodeHandle(this.refs.JSMeetupReactView), | |
UIManager.JSMeetupView.Commands.blah, | |
null | |
); | |
} | |
render() { | |
return <JSMeetupView | |
{...this.props} | |
ref="JSMeetupReactView" | |
/>; | |
}; | |
} | |
const JSMeetupView = requireNativeComponent('JSMeetupView', JSMeetupReactView, { | |
nativeOnly: { onChange: true } | |
}); | |
module.exports = JSMeetupReactView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JSMeetupView extends AnyComponent implements LifecycleEventListener { | |
public JSMeetupView(ReactApplicationContext context) { | |
super(context); | |
context.addLifecycleEventListener(this); | |
} | |
public void setInputUrl(String inputUrl) { | |
... | |
} | |
public void blah() { | |
... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JSMeetupViewManager extends SimpleViewManager<JSMeetupView> { | |
private JSMeetupView view; | |
public JSMeetupViewManager(ReactApplicationContext reactContext) { | |
view = new JSMeetupView(reactContext); | |
} | |
@Override | |
public String getName() { | |
return "JSMeetup"; | |
} | |
@Override | |
public JSMeetupView createViewInstance(ThemedReactContext reactContext) { | |
return view; | |
} | |
@ReactProp(name = "inputUrl") | |
public void setInputUrl(JSMeetupView view, @Nullable String inputUrl) { | |
view.setInputUrl(inputUrl); | |
} | |
@Override | |
public void receiveCommand(JSMeetupView root, int commandId, @Nullable ReadableArray args) { | |
switch (commandId) { | |
case "blah": | |
root.blah(); | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainApplication extends Application implements ReactApplication { | |
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { | |
@Override | |
public boolean getUseDeveloperSupport() { | |
return BuildConfig.DEBUG; | |
} | |
@Override | |
protected List<ReactPackage> getPackages() { | |
return Arrays.<ReactPackage>asList( | |
new MainReactPackage(), | |
new MeetupPackage() // this line ! | |
); | |
} | |
}; | |
@Override | |
public ReactNativeHost getReactNativeHost() { | |
return mReactNativeHost; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment