Skip to content
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(voltron): complete dart null safe and rename voltron framework #2541

Merged
merged 5 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion framework/voltron/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.voltron_render_example"
applicationId "com.example.voltron.voltron_example"
minSdkVersion 21
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.voltron_render_example">
package="com.example.voltron.voltron_example">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.voltron_render_example">
package="com.example.voltron.voltron_example">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
Expand All @@ -20,7 +20,7 @@
android:name="flutterEmbedding"
android:value="2" />
<activity
android:name="com.example.voltron_render.voltron_render_example.MainActivity"
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.voltron_render.voltron_render_example
package com.example.voltron.voltron_example

import io.flutter.embedding.android.FlutterActivity

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.voltron_render_example">
package="com.example.voltron.voltron_example">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
4 changes: 2 additions & 2 deletions framework/voltron/example/assets/jsbundle/index.android.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"hippyReactBase","content":{"../../packages/hippy-react/dist/index.js":{"id":"../../packages/hippy-react/dist/index.js","buildMeta":{"exportsType":"namespace","providedExports":["Animated","Animation","AnimationSet","AppRegistry","AsyncStorage","BackAndroid","Clipboard","ConsoleModule","Dimensions","Easing","Focusable","Hippy","HippyEventEmitter","HippyEventListener","HippyRegister","Image","ImageBackground","ImageLoaderModule","ListView","ListViewItem","Modal","Navigator","NetInfo","NetworkModule","PixelRatio","Platform","PullFooter","PullHeader","RefreshWrapper","ScrollView","StyleSheet","Text","TextInput","TimerModule","UIManagerModule","View","ViewPager","WaterfallView","WebSocket","WebView","callNative","callNativeWithCallbackId","callNativeWithPromise","colorParse","default","flushSync","removeNativeCallback"]}},"./node_modules/@hippy/react-reconciler/cjs/react-reconciler.production.min.js":{"id":"./node_modules/@hippy/react-reconciler/cjs/react-reconciler.production.min.js","buildMeta":{"providedExports":true}},"./node_modules/@hippy/react-reconciler/index.js":{"id":"./node_modules/@hippy/react-reconciler/index.js","buildMeta":{"providedExports":true}},"./node_modules/object-assign/index.js":{"id":"./node_modules/object-assign/index.js","buildMeta":{"providedExports":true}},"./node_modules/process/browser.js":{"id":"./node_modules/process/browser.js","buildMeta":{"providedExports":true}},"./node_modules/react/cjs/react.production.min.js":{"id":"./node_modules/react/cjs/react.production.min.js","buildMeta":{"providedExports":true}},"./node_modules/react/index.js":{"id":"./node_modules/react/index.js","buildMeta":{"providedExports":true}},"./node_modules/scheduler/cjs/scheduler.production.min.js":{"id":"./node_modules/scheduler/cjs/scheduler.production.min.js","buildMeta":{"providedExports":true}},"./node_modules/scheduler/index.js":{"id":"./node_modules/scheduler/index.js","buildMeta":{"providedExports":true}},"./node_modules/webpack/buildin/global.js":{"id":"./node_modules/webpack/buildin/global.js","buildMeta":{"providedExports":true}},"./node_modules/webpack/buildin/module.js":{"id":"./node_modules/webpack/buildin/module.js","buildMeta":{"providedExports":true}},"./scripts/vendor.js":{"id":"./scripts/vendor.js","buildMeta":{"providedExports":true}}}}
{"name":"hippyReactBase","content":{"../../packages/hippy-react/dist/index.js":{"id":"../../packages/hippy-react/dist/index.js","buildMeta":{"exportsType":"namespace","providedExports":["Animated","Animation","AnimationSet","AppRegistry","AsyncStorage","BackAndroid","Clipboard","ConsoleModule","Dimensions","Easing","Focusable","Hippy","HippyEventEmitter","HippyEventListener","HippyRegister","Image","ImageBackground","ImageLoaderModule","ListView","ListViewItem","Modal","Navigator","NetInfo","NetworkModule","PixelRatio","Platform","PullFooter","PullHeader","RNfqb","RNfqbEventEmitter","RNfqbEventListener","RNfqbRegister","RefreshWrapper","ScrollView","StyleSheet","Text","TextInput","TimerModule","UIManagerModule","View","ViewPager","WaterfallView","WebSocket","WebView","callNative","callNativeWithCallbackId","callNativeWithPromise","colorParse","default","flushSync","removeNativeCallback"]}},"./node_modules/@hippy/react-reconciler/cjs/react-reconciler.production.min.js":{"id":"./node_modules/@hippy/react-reconciler/cjs/react-reconciler.production.min.js","buildMeta":{"providedExports":true}},"./node_modules/@hippy/react-reconciler/index.js":{"id":"./node_modules/@hippy/react-reconciler/index.js","buildMeta":{"providedExports":true}},"./node_modules/object-assign/index.js":{"id":"./node_modules/object-assign/index.js","buildMeta":{"providedExports":true}},"./node_modules/react/cjs/react.production.min.js":{"id":"./node_modules/react/cjs/react.production.min.js","buildMeta":{"providedExports":true}},"./node_modules/react/index.js":{"id":"./node_modules/react/index.js","buildMeta":{"providedExports":true}},"./node_modules/scheduler/cjs/scheduler.production.min.js":{"id":"./node_modules/scheduler/cjs/scheduler.production.min.js","buildMeta":{"providedExports":true}},"./node_modules/scheduler/index.js":{"id":"./node_modules/scheduler/index.js","buildMeta":{"providedExports":true}},"./node_modules/webpack/buildin/global.js":{"id":"./node_modules/webpack/buildin/global.js","buildMeta":{"providedExports":true}},"./node_modules/webpack/buildin/module.js":{"id":"./node_modules/webpack/buildin/module.js","buildMeta":{"providedExports":true}},"./scripts/vendor.js":{"id":"./scripts/vendor.js","buildMeta":{"providedExports":true}}}}
16 changes: 8 additions & 8 deletions framework/voltron/example/assets/jsbundle/vendor.android.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions framework/voltron/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PODS:
- system_proxy (0.0.1):
- Flutter
- Toast (4.0.0)
- voltron_render (0.0.1):
- voltron (0.0.1):
- Flutter
- webview_flutter_wkwebview (0.0.1):
- Flutter
Expand All @@ -45,7 +45,7 @@ DEPENDENCIES:
- shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
- system_proxy (from `.symlinks/plugins/system_proxy/ios`)
- voltron_render (from `.symlinks/plugins/voltron_render/ios`)
- voltron (from `.symlinks/plugins/voltron/ios`)
- webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/ios`)

SPEC REPOS:
Expand Down Expand Up @@ -77,8 +77,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/sqflite/ios"
system_proxy:
:path: ".symlinks/plugins/system_proxy/ios"
voltron_render:
:path: ".symlinks/plugins/voltron_render/ios"
voltron:
:path: ".symlinks/plugins/voltron/ios"
webview_flutter_wkwebview:
:path: ".symlinks/plugins/webview_flutter_wkwebview/ios"

Expand All @@ -97,7 +97,7 @@ SPEC CHECKSUMS:
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904
system_proxy: bec1a5c5af67dd3e3ebf43979400a8756c04cc44
Toast: 91b396c56ee72a5790816f40d3a94dd357abc196
voltron_render: f78fa7bdb216b804bea16b216c7453c52973b6af
voltron: 573e6755e966a450ea768ab1074d237ad0f41d82
webview_flutter_wkwebview: b7e70ef1ddded7e69c796c7390ee74180182971f

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
Expand Down
210 changes: 4 additions & 206 deletions framework/voltron/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @dart=2.9
//
// Tencent is pleased to support the open source community by making
// Hippy available.
Expand All @@ -21,13 +20,9 @@

import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:voltron_render/voltron_render.dart';
import 'package:voltron_renderer/voltron_renderer.dart';

import 'page_test.dart';
import 'view/base_voltron_page.dart';

void main() {
_MyWidgetInspector.init();
Expand Down Expand Up @@ -58,208 +53,11 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Builder(
builder: (context) => Scaffold(
appBar: AppBar(
title: Text('Voltron动态化方案'),
backgroundColor: Color(0xFF40b883),
systemOverlayStyle: Platform.isAndroid
? SystemUiOverlayStyle.light.copyWith(
statusBarColor: Colors.black,
)
: null,
),
body: MainPageWidget(),
),
home: BaseVoltronPage(
coreBundle: "assets/jsbundle/vendor.android.js",
indexBundle: "assets/jsbundle/index.android.js",
),
);
// return MaterialApp(
// home: VoltronPage(),
// );
}
}

class VoltronPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _VoltronPageState();
}
}

class MainPageWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Container(
alignment: Alignment.topCenter,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
width: 350,
height: 150,
child: Image.asset('assets/voltron-logo.png'),
),
Card(
margin: EdgeInsets.only(left: 10, right: 10, top: 20, bottom: 0),
color: Colors.white,
child: Container(
padding: EdgeInsets.only(top: 12, bottom: 12, left: 8, right: 8),
child: Column(
children: [
Text('官方Demo', style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold)),
ButtonBar(
buttonHeight: 50,
alignment: MainAxisAlignment.center,
children: [
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PageTestWidget(),
),
);
},
child: Text('进入体验'),
)
],
),
],
),
),
),
Card(
margin: EdgeInsets.only(left: 10, right: 10, top: 20, bottom: 40),
color: Colors.white,
child: Container(
padding: EdgeInsets.only(top: 12, bottom: 12, left: 8, right: 8),
child: Column(
children: [
Text('本地调试', style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold)),
SizedBox(
height: 20,
),
SizedBox(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('1. 使用usb线链接Android手机和电脑,并启动Voltron'),
Text('2. 前端项目执行npm install安装依赖'),
Text('3. 前端项目执行npm run voltron:dev编译调试包'),
Text('4. 前端项目执行npm run voltron:debug链接手机并启动调试服务'),
Text('5. 点击下方开始调试进入调试页面'),
Text(
'6. 打开chrome://inspect,需要确保localhost:38989在Discover network targets右侧的Configuration弹窗中,下方会出现设备列表,点击inspect开始调试'),
],
),
),
ButtonBar(
alignment: MainAxisAlignment.center,
children: [
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PageTestWidget(
'http://localhost:38989/index.bundle',
true,
),
),
);
},
child: Text('进入调试'),
),
],
),
],
),
),
),
],
),
),
);
}
}

class _VoltronPageState extends State<VoltronPage> {
PageStatus pageStatus = PageStatus.init;
VoltronJSLoaderManager _loaderManager;
VoltronJSLoader _jsLoader;

@override
void initState() {
super.initState();
DeviceInfoPlugin().iosInfo.then((deviceData) {
var initParams = EngineInitParams();
initParams.debugMode = false;
initParams.enableLog = true;
initParams.coreJSAssetsPath = 'assets/bundle/vendor.js';
initParams.codeCacheTag = "common";
initParams.providers = [];
initParams.engineMonitor = Monitor();
_loaderManager = VoltronJSLoaderManager.createLoaderManager(
initParams,
(statusCode, msg) {
LogUtils.i(
'loadEngine',
'code($statusCode), msg($msg)',
);
if (statusCode == EngineInitStatus.ok) {
pageStatus = PageStatus.success;
setState(() {});
} else {
pageStatus = PageStatus.error;
setState(() {});
}
},
);
var loadParams = ModuleLoadParams();
loadParams.componentName = "Demo";
loadParams.codeCacheTag = "Demo";
loadParams.jsAssetsPath = 'assets/bundle/index.js';
loadParams.jsParams = VoltronMap();
loadParams.jsParams.push(
"msgFromNative",
"Hi js developer, I come from native code!",
);
if (Platform.isIOS) {
loadParams.jsParams.push(
"isSimulator",
!deviceData.isPhysicalDevice,
);
}

_jsLoader = _loaderManager.createLoader(
loadParams,
moduleListener: (status, msg) {
LogUtils.i(
"flutterRender",
"loadModule status($status), msg ($msg)",
);
},
);
}).catchError((err) {
pageStatus = PageStatus.error;
setState(() {});
});
}

@override
Widget build(BuildContext context) {
Widget child;
if (pageStatus == PageStatus.success) {
child = VoltronWidget(loader: _jsLoader);
} else {
child = Container();
}
return Material(
child: child,
);
}
}

Expand Down
31 changes: 26 additions & 5 deletions framework/voltron/example/lib/module/test_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
//

import 'package:flutter/material.dart';
import 'package:voltron_render/engine.dart';
import 'package:voltron_render/module.dart';

import '../page_test.dart';
import 'package:voltron/engine.dart';
import 'package:voltron/module.dart';
import '../view/base_voltron_page.dart';

class TestModule extends VoltronNativeModule {
static const String kModuleName = "TestModule";

static const String kDebugMethodName = "debug";
static const String kRemoteDebugMethodName = "remoteDebug";

TestModule(EngineContext context) : super(context);

Expand All @@ -38,7 +38,27 @@ class TestModule extends VoltronNativeModule {
Navigator.push(
rootBuildContext,
MaterialPageRoute(
builder: (context) => PageTestWidget('http://localhost:38989/index.bundle', true),
builder: (context) => BaseVoltronPage(
debugMode: true,
remoteServerUrl: 'http://localhost:38989/index.bundle',
),
),
);
}
return true;
}

@VoltronMethod(kDebugMethodName)
bool remoteDebug(int instanceId, String bundleUrl, JSPromise promise) {
var rootBuildContext = context.renderContext.getInstance(instanceId)?.currentContext;
if (rootBuildContext != null) {
Navigator.push(
rootBuildContext,
MaterialPageRoute(
builder: (context) => BaseVoltronPage(
debugMode: true,
remoteServerUrl: bundleUrl,
),
),
);
}
Expand All @@ -48,6 +68,7 @@ class TestModule extends VoltronNativeModule {
@override
Map<String, Function> get extraFuncMap => {
kDebugMethodName: debug,
kRemoteDebugMethodName: remoteDebug,
};

@override
Expand Down
4 changes: 2 additions & 2 deletions framework/voltron/example/lib/my_api_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
// limitations under the License.
//

import 'package:voltron_render/engine.dart';
import 'package:voltron_render_example/module/test_module.dart';
import 'package:voltron/voltron.dart';
import 'package:voltron_renderer/voltron_renderer.dart';
import './module/test_module.dart';

class MyAPIProvider implements APIProvider {
@override
Expand Down
Loading