setting up gradle plugin with DefaultTask to instantiate a class that renders react-native - react-native

I am trying to build a module with gradle that starts up a react-native app in a native app. Im following a guide that explains that a class extending from DefaultTask is responsible for the root behavior of the plugin. Going off of that, I want to do something with a file like this. start react app class . Am I on the right track?
public class DemoTask extends DefaultTask {
#TaskAction
public void renderRNSDK() {
}
}

Related

Where can I find my MainActivity.java when running a Android simulator

I just mad my first React native project and I'm trying to lock my screen orientation to landscape. I installed this package
https://github.com/yamill/react-native-orientation#configuration
with npm install react-native link react-native-orientation and now I need to
Implement onConfigurationChanged method in MainActivity.java
So this code
import android.content.Intent; // <--- import
import android.content.res.Configuration; // <--- import
public class MainActivity extends ReactActivity {
......
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Intent intent = new Intent("onConfigurationChanged");
intent.putExtra("newConfig", newConfig);
this.sendBroadcast(intent);
}
......
}
But where can I find that? From what I've seen is that you can find it in a android studio project. But I don't have a project, I just go to the AVD manager to run my virtual device. So where am I supposed to add this code?
The whole aim of expo is to handle everything related to android or ios for you.
Thus, you won't have access to these two folders unless you eject your app from expo as it's explained here on the official doc.
However, if your goal is to handle screen orientation, expo has a built-in API for you that you may find here.
Or even simpler, you could just update your app.json and add this line:
"expo": {
...
"orientation": "landscape"
...
}
Have a look at the official doc if you want to see everything that you can handle with this configuration file.

Passing data to react-native from native with proguard

Without proguard=true following is WritableMap which is passed to React native.
{isDone:true}
And I enable obfuscation
{a:true}
I want pro guard not to touch this class. What to add in proguard file?
Add following to proguard-rules.pro:
-keep, includedescriptorclasses public class packagename.model.** {*; }

Change IntelliJ Run Configuration Environment Variables with Plugin

I am trying to build a plugin for IntelliJ that when pressing a button, it will load env vars from the web to the current Run Configuration.
I couldn't find a way to reach the current Run Configuration, let alone to edit the env vars.
When trying to create new Action all I get as a parameter is a AnActionEvent and I couldn't find anything useful there
public class HelloAction extends AnAction {
public HelloAction() {
super("Hello");
}
#Override
public void actionPerformed(AnActionEvent event) {
Project project = event.getProject();
}
}
I would be happy for any clue here
To get the current run configuration, use RunManager.getInstance(project).getSelectedConfiguration().getConfiguration(). Then check if the returned object implements CommonProgramRunConfigurationParameters, and if it does, call the setEnvs method of this interface to change the environment variables.

react-native : Native modules with same name for both android and iOS

I'm trying to build a react-native wrapper around our existing native android and ios SDK. I want to know if I can use the same class name and class methods for both the Android and iOS bridge modules? And how do I map the right module to be called for the right device?
For instance, for iOS :
// CalendarManager.h
#import "RCTBridgeModule.h"
#interface CalendarManager : NSObject <RCTBridgeModule>
#end
// CalendarManager.m
#implementation CalendarManager
RCT_EXPORT_MODULE();
#end
RCT_EXPORT_METHOD(addEvent:(NSString *)name location:(NSString *)location)
{
//Some work
}
For Android :
public class CalendarManager extends ReactContextBaseJavaModule {
public CalendarManager(ReactApplicationContext reactContext) {
super(reactContext);
}
#Override
public String getName() {
return "CalendarManager";
}
#ReactMethod
public void addEvent(String name, String location) {
//Some work
}
}
And in my js file, if I have something like this :
import { NativeModules } from 'react-native';
NativeModules.CalendarManager.addEvent("Name", "Location")
Which one will be executed? Is there a way where I could route it to the right function based on the device?
Thanks.
You don't have to do that routing yourself. That is build into React-Native. It knows which type of device you're on.
React Native packages a different version of the code that you have in your project according to the target platform that you set when you create the application APK or IPA. That is, when you do react native run-android for instance, it will compile the native Java code present in the Android project located in the android folder and pack the APK with that. Then JavaScript will have access to the native Java code. Same thing for iOS with the Objective-C/Swift code. So yes, you can (actually, I'd say you must) use the same name for the native modules.

How to set CRUD in a subpackage with Play

I am trying to use the CRUD module in subpackages instead of the default one.
package controllers.admin;
import models.Branch;
import controllers.CRUD;
#CRUD.For(Branch.class)
public class Branches extends CRUD {
public static void index() {
render();
}
}
My routes file is:
# Import CRUD routes
* /admin module:crud
However when I use the default url: http://localhost:9000/admin/
I get the template not found error:
Template not found
The template admin/Branches/index.html does not exist.
How can I specify to CRUD module to look for views in the subpackages?
ok. controller was generated with eclipse plugin and included the index() method.
Removing it solved the problem and the module is now working correctly.