Skip to content

Commit 7d3bb44

Browse files
committed
added: ensemble app
1 parent 162ab98 commit 7d3bb44

30 files changed

+16255
-25
lines changed

android/build.gradle

+17
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ android {
6969
release {
7070
minifyEnabled false
7171
}
72+
profile {
73+
initWith debug
74+
}
75+
7276
}
7377

7478
lintOptions {
@@ -98,6 +102,14 @@ android {
98102
repositories {
99103
mavenCentral()
100104
google()
105+
106+
maven {
107+
url "../ensemble_app/build/host/outputs/repo"
108+
}
109+
maven {
110+
url "https://storage.googleapis.com/download.flutter.io"
111+
}
112+
101113
}
102114

103115

@@ -106,6 +118,11 @@ dependencies {
106118
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
107119
//noinspection GradleDynamicVersion
108120
implementation "com.facebook.react:react-native:+"
121+
122+
debugImplementation 'com.ensembleui.ensemble_app:flutter_debug:1.0'
123+
profileImplementation 'com.ensembleui.ensemble_app:flutter_profile:1.0'
124+
releaseImplementation 'com.ensembleui.ensemble_app:flutter_release:1.0'
125+
109126
}
110127

111128
if (isNewArchitectureEnabled()) {

android/src/main/AndroidManifest.xml

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.ensemblereactnative">
3+
<application>
4+
<activity
5+
android:name="io.flutter.embedding.android.FlutterActivity"
6+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
7+
android:hardwareAccelerated="true"
8+
android:windowSoftInputMode="adjustResize"
9+
/>
10+
</application>
311
</manifest>
+9
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<application>
3+
<activity
4+
android:name="io.flutter.embedding.android.FlutterActivity"
5+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
6+
android:hardwareAccelerated="true"
7+
android:windowSoftInputMode="adjustResize"
8+
/>
9+
</application>
210
</manifest>
11+

android/src/main/java/com/ensemblereactnative/EnsembleReactNativeModule.java

+53-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,53 @@
66
import com.facebook.react.bridge.ReactApplicationContext;
77
import com.facebook.react.bridge.ReactMethod;
88

9+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
10+
import com.facebook.react.module.annotations.ReactModule;
11+
import io.flutter.embedding.android.FlutterActivity;
12+
import io.flutter.embedding.engine.FlutterEngine;
13+
import io.flutter.embedding.engine.FlutterEngineCache;
14+
import io.flutter.embedding.engine.dart.DartExecutor;
15+
import android.app.Activity;
16+
917
public class EnsembleReactNativeModule extends EnsembleReactNativeSpec {
1018
public static final String NAME = "EnsembleReactNative";
19+
private final ReactApplicationContext reactContext;
20+
public FlutterEngine flutterEngine;
1121

1222
EnsembleReactNativeModule(ReactApplicationContext context) {
1323
super(context);
24+
this.reactContext = context;
25+
new Thread(new Runnable() {
26+
@Override
27+
public void run() {
28+
try {
29+
//dummy delay
30+
Thread.sleep(100);
31+
} catch (InterruptedException e) {
32+
e.printStackTrace();
33+
}
34+
35+
//Update ui on UI thread
36+
reactContext.getCurrentActivity().runOnUiThread(new Runnable() {
37+
@Override
38+
public void run() {
39+
// Instantiate a FlutterEngine.
40+
flutterEngine = new FlutterEngine(reactContext.getApplicationContext());
41+
42+
// Start executing Dart code to pre-warm the FlutterEngine.
43+
flutterEngine.getDartExecutor().executeDartEntrypoint(
44+
DartExecutor.DartEntrypoint.createDefault()
45+
);
46+
47+
// Cache the FlutterEngine to be used by FlutterActivity.
48+
FlutterEngineCache
49+
.getInstance()
50+
.put(NAME, flutterEngine);
51+
}
52+
});
53+
54+
}
55+
}).start();
1456
}
1557

1658
@Override
@@ -20,10 +62,19 @@ public String getName() {
2062
}
2163

2264

23-
// Example method
24-
// See https://reactnative.dev/docs/native-modules-android
2565
@ReactMethod
2666
public void multiply(double a, double b, Promise promise) {
2767
promise.resolve(a * b);
2868
}
69+
70+
@ReactMethod
71+
public void openEnsembleApp(Promise promise) {
72+
Activity currentActivity = reactContext.getCurrentActivity();
73+
74+
currentActivity.startActivity(
75+
FlutterActivity
76+
.withCachedEngine(NAME)
77+
.build(currentActivity)
78+
);
79+
}
2980
}

android/src/oldarch/EnsembleReactNativeSpec.java

+2
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ abstract class EnsembleReactNativeSpec extends ReactContextBaseJavaModule {
1010
}
1111

1212
public abstract void multiply(double a, double b, Promise promise);
13+
public abstract void openEnsembleApp(Promise promise);
14+
1315
}

ensemble_app/.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yourEnv=yourValue

ensemble_app/.gitignore

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.DS_Store
2+
.dart_tool/
3+
4+
.pub/
5+
6+
.idea/
7+
.vagrant/
8+
.sconsign.dblite
9+
.svn/
10+
11+
migrate_working_dir/
12+
13+
*.swp
14+
profile
15+
16+
DerivedData/
17+
18+
.generated/
19+
20+
*.pbxuser
21+
*.mode1v3
22+
*.mode2v3
23+
*.perspectivev3
24+
25+
!default.pbxuser
26+
!default.mode1v3
27+
!default.mode2v3
28+
!default.perspectivev3
29+
30+
xcuserdata
31+
32+
*.moved-aside
33+
34+
*.pyc
35+
*sync/
36+
Icon?
37+
.tags*
38+
39+
build/
40+
.android/
41+
.ios/
42+
.flutter-plugins
43+
.flutter-plugins-dependencies
44+
45+
# Symbolication related
46+
app.*.symbols
47+
48+
# Obfuscation related
49+
app.*.map.json

ensemble_app/.metadata

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "300451adae589accbece3490f4396f10bdf15e6e"
8+
channel: "stable"
9+
10+
project_type: module

ensemble_app/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ensemble_app
2+
3+
A new Flutter module project.
4+
5+
## Getting Started
6+
7+
For help getting started with Flutter development, view the online
8+
[documentation](https://flutter.dev/).
9+
10+
For instructions integrating Flutter modules to your existing applications,
11+
see the [add-to-app documentation](https://flutter.dev/docs/development/add-to-app).

ensemble_app/analysis_options.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
View:
2+
body:
3+
Column:
4+
children:
5+
- Text:
6+
styles: { fontSize: 20 }
7+
text: See you later
8+
9+
- Button:
10+
label: Go Home
11+
onTap:
12+
action: navigateScreen
13+
name: Hello Home
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
View:
2+
styles:
3+
useSafeArea: true
4+
5+
# Optional - set the header for the screen
6+
header:
7+
titleText: Home
8+
9+
# Specify the body of the screen
10+
body:
11+
Column:
12+
styles:
13+
padding: 24
14+
gap: 8
15+
children:
16+
- Text:
17+
text: Hi there!
18+
- Button:
19+
label: Checkout Ensemble Kitchen Sink
20+
onTap:
21+
openUrl:
22+
url: 'https://studio.ensembleui.com/preview/index.html?appId=e24402cb-75e2-404c-866c-29e6c3dd7992'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Widgets:
2+
# this widget can be referenced using MyCustomWidget1
3+
MyCustomWidget1:
4+
Import:
5+
- apiUtils
6+
- common
7+
inputs:
8+
- inputName
9+
body:
10+
Column:
11+
children:
12+
- Text:
13+
text: ${inputName.first} ${inputName.last}
14+
- Button:
15+
label: sayHello in console
16+
onTap: |-
17+
saveName('Jane','Doe');
18+
console.log('name:'+getName());
19+
- MyCustomWidget2:
20+
inputs:
21+
customProperty: ${ensemble.storage.helloApp.name.first}
22+
MyCustomWidget2:
23+
inputs:
24+
- customProperty
25+
body:
26+
Column:
27+
children:
28+
- Text:
29+
text: ${customProperty}
30+
31+
Scripts:
32+
utils: |-
33+
var apiUtilsCount = 0;
34+
function callMockMethod() {
35+
apiUtilsCount++;
36+
console.log('apiUtilsCount='+apiUtilsCount);
37+
}
38+
common: |-
39+
function sayHello(name) {
40+
console.log('sayHello:'+name);
41+
}
42+
function saveName(first,last) {
43+
ensemble.storage.helloApp = {name: {first: first, last: last}};
44+
}
45+
function getName() {
46+
if ( ensemble.storage.helloApp != null ) {
47+
return ensemble.storage.helloApp.name;
48+
}
49+
return null;
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
colors:
2+
primary:
3+
secondary:
4+
301 KB
Loading

0 commit comments

Comments
 (0)