-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Android): Refactoring configuration #3778
Conversation
Conflicts: android/capacitor/src/main/java/com/getcapacitor/Bridge.java android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java
android/capacitor/src/main/java/com/getcapacitor/CapConfig.java
Outdated
Show resolved
Hide resolved
loadConfig(assetManager); | ||
deserializeConfig(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should all this be happening in the constructor? Maybe we can take this opportunity to practice some separation of concerns. The iOS side now has a few different classes that separate "loading from a JSON file" and "containing the configuration".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. I have removed the public constructor for CapConfig and replaced it with a method fromFile
that can be used to create an instance of CapConfig from the JSON config file.
I moved the JSON file loading to the FileUtils class since it involved reading a file and seemed appropriate there (and its also reused elsewhere in the core).
android/capacitor/src/main/java/com/getcapacitor/CapConfig.java
Outdated
Show resolved
Hide resolved
android/capacitor/src/main/java/com/getcapacitor/CapConfig.java
Outdated
Show resolved
Hide resolved
android/capacitor/src/main/java/com/getcapacitor/CapConfig.java
Outdated
Show resolved
Hide resolved
android/capacitor/src/main/java/com/getcapacitor/CapConfig.java
Outdated
Show resolved
Hide resolved
android/capacitor/src/main/java/com/getcapacitor/CapConfig.java
Outdated
Show resolved
Hide resolved
android/capacitor/src/main/java/com/getcapacitor/CapConfig.java
Outdated
Show resolved
Hide resolved
android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CapConfig was created to avoid a breaking change as we had the Config class and users were using it on plugins. Used CapConfig as the name to also match iOS name.
Since this PR changes the constructor, that's also a breaking change.
Not sure if instead of changing the constructor, we rename the class to InstanceConfiguration
as Ian did on the iOS equivalent #3759
It is a breaking change, but is it expected that 3rd parties would be creating new instances of CapConfig? I updated the code in the core to use the new constructor. If it's not an expected use-case or an embedded/edge case, it might be an acceptable breaking change. I can see the appeal in naming things similarly to iOS, but I don't think it should be the rule. Java has instances of classes so the name "InstanceConfiguration" feels unnecesarily verbose, but we are likely introducing a new class here to contain the plugin config, so we do need some name work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both platforms should be as close as possible, specially when two classes do the exact same thing. If not, when somebody not familiar with one of the two platforms needs to do some change in the other platform will have a hard time finding things.
But if you don't agree I'm ok with it.
@@ -39,7 +39,7 @@ protected void init(Bundle savedInstanceState, List<Class<? extends Plugin>> plu | |||
* use {@link BridgeActivity#bridgeBuilder}. | |||
*/ | |||
@Deprecated | |||
protected void init(Bundle savedInstanceState, List<Class<? extends Plugin>> plugins, JSONObject config) { | |||
protected void init(Bundle savedInstanceState, List<Class<? extends Plugin>> plugins, CapConfig config) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is already a breaking change, we should just remove it. init()
is the deprecated way of initializing the Android bridge.
This branch seeks to improve the config use in Android similar to #3759.
ConfigBuilder
for embedded use casegetInt
andgetString
are deprecated.getPluginInt
andgetPluginString
.getServerUrl
andgetBackgroundColor