Skip to content

Commit ff3d757

Browse files
refactor: revert unnecessary changes
1 parent 621c85f commit ff3d757

5 files changed

Lines changed: 136 additions & 11 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.facebook.react.devsupport
2+
3+
import com.facebook.react.modules.debug.interfaces.DeveloperSettings
4+
import com.mendix.mendixnative.activity.MendixReactActivity
5+
import com.mendix.mendixnative.util.ReflectionUtils
6+
7+
fun getDevInternalSettings(activity: MendixReactActivity): DeveloperSettings? =
8+
(activity.currentDevSupportManager as? DevSupportManagerBase)?.let {
9+
return ReflectionUtils.getField<DeveloperSettings>(it, "mDevSettings")
10+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.facebook.react.devsupport
2+
3+
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener
4+
import com.facebook.react.devsupport.interfaces.DevSupportManager
5+
import com.mendix.mendixnative.util.ReflectionUtils
6+
7+
fun setBundleDownloadListener(
8+
devSupportManager: DevSupportManager?,
9+
listener: DevBundleDownloadListener
10+
) {
11+
devSupportManager?.apply {
12+
ReflectionUtils.setFieldOfSuperclass(
13+
this,
14+
listener,
15+
"mBundleDownloadListener",
16+
"devBundleDownloadListener"
17+
)
18+
}
19+
}
20+
21+
fun overrideDevLoadingViewController(
22+
devSupportManager: DevSupportManager,
23+
devLoadingViewController: DefaultDevLoadingViewImplementation
24+
) {
25+
devSupportManager.apply {
26+
ReflectionUtils.setFieldOfSuperclass(
27+
this,
28+
devLoadingViewController,
29+
"mDevLoadingViewManager",
30+
"devLoadingViewManager"
31+
)
32+
}
33+
}

android/src/main/java/com/mendix/mendixnative/util/ReflectionUtils.java

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.mendix.mendixnative.util;
22

3+
import java.lang.reflect.Constructor;
34
import java.lang.reflect.Field;
5+
import java.lang.reflect.InvocationTargetException;
6+
import java.lang.reflect.Method;
47

58
public class ReflectionUtils {
69
private static Field findDeclaredField(Class<?> objectClass, String... fieldNames) {
@@ -17,17 +20,76 @@ private static Field findDeclaredField(Class<?> objectClass, String... fieldName
1720
throw new RuntimeException(lastException);
1821
}
1922

23+
public static ConstructorWrapper findConstructor(String className, Class<?>... parameterTypes) {
24+
try {
25+
Constructor constructor = Class.forName(className).getDeclaredConstructor(parameterTypes);
26+
constructor.setAccessible(true);
27+
return new ConstructorWrapper(constructor);
28+
} catch (ClassNotFoundException | NoSuchMethodException e) {
29+
throw new RuntimeException(e);
30+
}
31+
}
32+
33+
// TODO: replace this with a lambda after upgrading to Java 8
34+
public static class ConstructorWrapper {
35+
private final Constructor constructor;
36+
37+
ConstructorWrapper(Constructor constructor) {
38+
this.constructor = constructor;
39+
}
40+
41+
public <T> T newInstance(Object... args) {
42+
try {
43+
return (T) constructor.newInstance(args);
44+
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
45+
throw new RuntimeException(e);
46+
}
47+
}
48+
}
49+
50+
public static MethodWrapper findMethod(Object object, String methodName, Class<?>... parameterTypes) {
51+
try {
52+
Method method = object.getClass().getDeclaredMethod(methodName, parameterTypes);
53+
method.setAccessible(true);
54+
return new MethodWrapper(method, object);
55+
} catch (NoSuchMethodException e) {
56+
throw new RuntimeException(e);
57+
}
58+
}
59+
60+
// TODO: replace this with a lambda after upgrading to Java 8
61+
public static class MethodWrapper {
62+
private final Method method;
63+
private final Object object;
64+
65+
MethodWrapper(Method method, Object object) {
66+
this.method = method;
67+
this.object = object;
68+
}
69+
70+
public void invoke(Object... args) {
71+
try {
72+
method.invoke(object, args);
73+
} catch (IllegalAccessException | InvocationTargetException e) {
74+
throw new RuntimeException(e);
75+
}
76+
}
77+
}
78+
79+
public static void setFieldOfSuperclass(Object object, String fieldName, Object value) {
80+
setFieldOfSuperclass(object, value, fieldName);
81+
}
82+
2083
public static void setFieldOfSuperclass(Object object, Object value, String... fieldNames) {
2184
Field field = findDeclaredField(object.getClass().getSuperclass(), fieldNames);
2285
setField(object, field, value);
2386
}
2487

25-
public static <T> T getFieldOfSuperclass(Object object, String... fieldNames) {
88+
public static void setField(Object object, String fieldName, Object value) {
2689
try {
27-
Field field = findDeclaredField(object.getClass().getSuperclass(), fieldNames);
28-
field.setAccessible(true);
29-
return (T) field.get(object);
30-
} catch (IllegalAccessException | ClassCastException e) {
90+
Field field = object.getClass().getDeclaredField(fieldName);
91+
setField(object, field, value);
92+
} catch (NoSuchFieldException e) {
3193
throw new RuntimeException(e);
3294
}
3395
}
@@ -42,4 +104,29 @@ private static void setField(Object object, Field field, Object value) {
42104
field.setAccessible(false);
43105
}
44106
}
107+
108+
public static <T> T getFieldOfSuperclass(Object object, String fieldName) {
109+
return getFieldOfSuperclass(object, new String[] { fieldName });
110+
}
111+
112+
public static <T> T getFieldOfSuperclass(Object object, String... fieldNames) {
113+
try {
114+
Field field = findDeclaredField(object.getClass().getSuperclass(), fieldNames);
115+
field.setAccessible(true);
116+
return (T) field.get(object);
117+
} catch (IllegalAccessException | ClassCastException e) {
118+
throw new RuntimeException(e);
119+
}
120+
}
121+
122+
public static <T> T getField(Object object, String fieldName) {
123+
try {
124+
Field field = object.getClass().getDeclaredField(fieldName);
125+
field.setAccessible(true);
126+
return (T) field.get(object);
127+
} catch (NoSuchFieldException | IllegalAccessException | ClassCastException e) {
128+
throw new RuntimeException(e);
129+
}
130+
}
131+
45132
}

ios/Modules/Helper/ReactAppProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ open class ReactAppProvider: UIResponder, UIApplicationDelegate {
2626
delegate.dependencyProvider = RCTAppDependencyProvider()
2727
reactNativeDelegate = delegate
2828
reactNativeFactory = factory
29-
window = MendixReactWindow(frame: UIScreen.main.bounds)
29+
window = UIWindow(frame: UIScreen.main.bounds)
3030
}
3131

3232
open func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

ios/Modules/MendixReactWindow/MendixReactWindow.swift

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)