Skip to content

Commit

Permalink
Merge branch 'main' into input_keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli authored Nov 16, 2023
2 parents fc196d6 + f4fcc99 commit 25859aa
Show file tree
Hide file tree
Showing 35 changed files with 323 additions and 132 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ CMakeLists.txt @ilikethese @etkmao
/framework/examples/android-demo/res/ @zealotchen0
/framework/examples/ios-demo/ @wwwcg @ruifanyuan
/framework/examples/ios-demo/res/ @zealotchen0
/framework/examples/voltron-demo/ @henryjin0511

# doc: pages
/*.md @zealotchen0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ public void updateDimension(int width, int height, boolean shouldUseScreenDispla
systemUiVisibilityChanged);
}
}
DimensionsUtil.convertDimensionsToDp(dimensionMap);
if (mEngineContext.getModuleManager() != null) {
mEngineContext.getModuleManager().getJavaScriptModule(Dimensions.class)
.set(dimensionMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.openhippy.connector.JsDriver.V8InitParams;
import com.openhippy.connector.NativeCallback;
import com.openhippy.framework.BuildConfig;
import com.tencent.mtt.hippy.HippyEngine;
import com.tencent.mtt.hippy.HippyEngine.ModuleLoadStatus;
import com.tencent.mtt.hippy.HippyEngineContext;
import com.tencent.mtt.hippy.adapter.thirdparty.HippyThirdPartyAdapter;
Expand Down Expand Up @@ -508,6 +507,7 @@ String getGlobalConfigs() {
.reviseDimensionIfNeed(context, dimensionMap, false,
false);
}
DimensionsUtil.convertDimensionsToDp(dimensionMap);
globalParams.pushMap("Dimensions", dimensionMap);

String packageName = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase;
import com.tencent.mtt.hippy.runtime.builtins.JSObject;
import com.tencent.vfs.ResourceDataHolder;
import com.tencent.vfs.ResourceDataHolder.TransferType;
import com.tencent.vfs.VfsManager;
import com.tencent.vfs.VfsManager.FetchResourceCallback;
import java.nio.charset.StandardCharsets;
Expand All @@ -54,7 +53,7 @@ public NetworkModule(HippyEngineContext context) {
}

@SuppressWarnings("deprecation")
private void normalizeRequestHeaders(@NonNull HippyMap headers,
protected void normalizeRequestHeaders(@NonNull HippyMap headers,
@NonNull HashMap<String, String> requestHeaders) {
Set<Entry<String, Object>> entrySet = headers.entrySet();
for (Entry<String, Object> entry : entrySet) {
Expand Down Expand Up @@ -82,7 +81,7 @@ private void normalizeRequestHeaders(@NonNull HippyMap headers,
}

@SuppressWarnings("deprecation")
private void normalizeRequest(@NonNull HippyMap request,
protected void normalizeRequest(@NonNull HippyMap request,
@NonNull HashMap<String, String> requestHeaders,
@NonNull HashMap<String, String> requestParams) throws IllegalStateException {
Set<Entry<String, Object>> entrySet = request.entrySet();
Expand All @@ -103,7 +102,7 @@ private void normalizeRequest(@NonNull HippyMap request,
}
}

private void handleFetchResponse(@NonNull ResourceDataHolder dataHolder, Promise promise)
protected void handleFetchResponse(@NonNull ResourceDataHolder dataHolder, Promise promise)
throws IllegalStateException {
JSObject responseObject = new JSObject();
int statusCode = 0;
Expand Down Expand Up @@ -151,12 +150,12 @@ public void fetch(final HippyMap request, final Promise promise) {
try {
normalizeRequest(request, requestHeaders, requestParams);
} catch (Exception e) {
promise.resolve(e.getMessage());
promise.reject(e.getMessage());
return;
}
final String uri = requestParams.get(HTTP_URL);
if (TextUtils.isEmpty(uri)) {
promise.resolve("Get url parameter failed!");
promise.reject("Get url parameter failed!");
return;
}
vfsManager.fetchResourceAsync(uri, requestHeaders, requestParams,
Expand All @@ -168,12 +167,13 @@ public void onFetchCompleted(@NonNull ResourceDataHolder dataHolder) {
try {
handleFetchResponse(dataHolder, promise);
} catch (IllegalStateException e) {
promise.resolve(
"Handle response failed: " + dataHolder.errorMessage);
promise.reject(
"Handle response failed: " + e.getMessage());
}
} else {
promise.resolve(
"Load remote resource failed: " + dataHolder.errorMessage);
String error = TextUtils.isEmpty(dataHolder.errorMessage)
? "Load remote resource failed!" : dataHolder.errorMessage;
promise.resolve(error);
}
dataHolder.recycle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@

static NSString *const engineKey = @"Demo";

static NSString *formatLog(NSDate *timestamp, HippyLogLevel level, NSString *fileName, NSNumber *lineNumber, NSString *message) {
static NSArray *logLevelMap = @[@"TRACE", @"INFO", @"WARN", @"ERROR", @"FATAL"];
static NSDateFormatter *formatter;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
formatter = [NSDateFormatter new];
formatter.dateFormat = formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss.SSS";
});

NSString *levelStr = level < 0 || level > logLevelMap.count ? logLevelMap[1] : logLevelMap[level];

if(fileName){
return [[NSString alloc] initWithFormat:@"[%@][%@:%d][%@]%@",
[formatter stringFromDate:timestamp],
fileName.lastPathComponent,
lineNumber.intValue,
levelStr,
message
];
}else{
return [[NSString alloc] initWithFormat:@"[%@]%@",
[formatter stringFromDate:timestamp],
message
];
}
}

@interface HippyDemoViewController () <HippyMethodInterceptorProtocol, HippyBridgeDelegate, HippyRootViewDelegate> {
DriverType _driverType;
RenderType _renderType;
Expand Down Expand Up @@ -99,7 +126,12 @@ - (void)viewDidLoad {

- (void)registerLogFunction {
HippySetLogFunction(^(HippyLogLevel level, HippyLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
NSLog(@"hippy says:%@ in file %@ at line %@", message, fileName, lineNumber);
NSString *log = formatLog([NSDate date], level, fileName, lineNumber, message);
if([log hasSuffix:@"\n"]){
fprintf(stderr, "%s", log.UTF8String);
}else{
fprintf(stderr, "%s\n", log.UTF8String);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objectVersion = 55;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -229,7 +229,7 @@
};
};
buildConfigurationList = C2DC03F32A3EE271004B7147 /* Build configuration list for PBXProject "IOSProj" */;
compatibilityVersion = "Xcode 14.0";
compatibilityVersion = "Xcode 13.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,35 @@
import android.view.View;
import android.widget.Button;

import java.util.concurrent.atomic.AtomicLong;

import io.flutter.Log;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.dart.DartExecutor;

public class MainActivity extends AppCompatActivity {
private final AtomicLong idCounter = new AtomicLong(0);
private long currentEngineId;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createNewEngine();

Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openWithNewEngine();
}
});
}

void createNewEngine() {
currentEngineId = idCounter.incrementAndGet();

// Instantiate a FlutterEngine.
FlutterEngine flutterEngine = new FlutterEngine(this);
Expand All @@ -45,16 +63,16 @@ protected void onCreate(Bundle savedInstanceState) {
// Cache the FlutterEngine to be used by FlutterActivity.
FlutterEngineCache
.getInstance()
.put("my_engine_id", flutterEngine);
.put("my_engine_id_" + currentEngineId, flutterEngine);
}

Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(
FlutterActivity.withCachedEngine("my_engine_id").destroyEngineWithActivity(true).build(MainActivity.this)
);
}
});
void openWithNewEngine() {
startActivity(
FlutterActivity
.withCachedEngine("my_engine_id_" + currentEngineId)
.destroyEngineWithActivity(true)
.build(MainActivity.this)
);
createNewEngine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class _BaseVoltronPageState extends State<BaseVoltronPage> {
initParams.coreJSAssetsPath = _coreBundle;
initParams.codeCacheTag = "common";
}
initParams.integratedMode = IntegratedMode.flutterModule;
initParams.providers = [
MyAPIProvider(),
];
Expand Down
3 changes: 1 addition & 2 deletions framework/examples/voltron-demo/flutter_module/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ environment:
dependencies:
flutter:
sdk: flutter
voltron:
path: ../../../voltron
voltron: 0.0.37
qr_flutter: 4.0.0

# The following adds the Cupertino Icons font to your application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class _BaseVoltronPageState extends State<BaseVoltronPage> {
initParams.coreJSAssetsPath = _coreBundle;
initParams.codeCacheTag = "common";
}
initParams.integratedMode = IntegratedMode.flutterApp;
initParams.providers = [
MyAPIProvider(),
];
Expand Down
3 changes: 1 addition & 2 deletions framework/examples/voltron-demo/flutter_proj/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ dev_dependencies:
flutter_test:
sdk: flutter

voltron: ^0.0.29

voltron: 0.0.37
qr_flutter: 4.0.0

# The "flutter_lints" package below contains a set of recommended lints to
Expand Down
6 changes: 3 additions & 3 deletions framework/ios/base/bridge/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ - (void)loadBundleURL:(NSURL *)bundleURL
}
return;
}
HippyLogInfo(@"Begin loading bundle(%s) at %s", HP_CSTR_NOT_NULL(bundleURL.absoluteString.lastPathComponent.UTF8String), HP_CSTR_NOT_NULL(bundleURL.absoluteString.UTF8String));
HippyLogInfo(@"[HP PERF] Begin loading bundle(%s) at %s", HP_CSTR_NOT_NULL(bundleURL.absoluteString.lastPathComponent.UTF8String), HP_CSTR_NOT_NULL(bundleURL.absoluteString.UTF8String));
[_bundleURLs addObject:bundleURL];
dispatch_async(HippyBridgeQueue(), ^{
[self beginLoadingBundle:bundleURL completion:completion];
Expand Down Expand Up @@ -509,15 +509,15 @@ - (void)loadInstanceForRootView:(NSNumber *)rootTag withProperties:(NSDictionary
- (void)innerLoadInstanceForRootView:(NSNumber *)rootTag withProperties:(NSDictionary *)props {
HippyAssert(_moduleName, @"module name must not be null");
HippyLogInfo(@"[Hippy_OC_Log][Life_Circle],Running application %@ (%@)", _moduleName, props);
HippyLogInfo(@"Begin loading instance for HippyBridge(%p)", self);
HippyLogInfo(@"[HP PERF] Begin loading instance for HippyBridge(%p)", self);
NSDictionary *param = @{@"name": _moduleName,
@"id": rootTag,
@"params": props ?: @{},
@"version": _HippySDKVersion};
footstone::value::HippyValue value = [param toHippyValue];
std::shared_ptr<footstone::value::HippyValue> domValue = std::make_shared<footstone::value::HippyValue>(value);
self.javaScriptExecutor.pScope->LoadInstance(domValue);
HippyLogInfo(@"End loading instance for HippyBridge(%p)", self);
HippyLogInfo(@"[HP PERF] End loading instance for HippyBridge(%p)", self);
}

- (void)rootViewSizeChangedEvent:(NSNumber *)tag params:(NSDictionary *)params {
Expand Down
12 changes: 12 additions & 0 deletions framework/voltron/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 0.0.37

- resolve merge conflicts

## 0.0.36

- update ffi_manager

## 0.0.35

- update voltron_render to 0.0.25 to make flutter module faster

## 0.0.34

- support voltron dynamic library load
Expand Down
18 changes: 12 additions & 6 deletions framework/voltron/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ PODS:
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- sqflite (0.0.2):
- sqflite (0.0.3):
- Flutter
- FMDB (>= 2.7.5)
- voltron (0.0.1):
- Flutter
- voltron_screen_info (0.0.1):
- Flutter
- webview_cookie_manager (0.0.1):
- Flutter
- webview_flutter_wkwebview (0.0.1):
Expand All @@ -42,6 +44,7 @@ DEPENDENCIES:
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
- voltron (from `.symlinks/plugins/voltron/ios`)
- voltron_screen_info (from `.symlinks/plugins/voltron_screen_info/ios`)
- webview_cookie_manager (from `.symlinks/plugins/webview_cookie_manager/ios`)
- webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/ios`)

Expand Down Expand Up @@ -71,6 +74,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/sqflite/ios"
voltron:
:path: ".symlinks/plugins/voltron/ios"
voltron_screen_info:
:path: ".symlinks/plugins/voltron_screen_info/ios"
webview_cookie_manager:
:path: ".symlinks/plugins/webview_cookie_manager/ios"
webview_flutter_wkwebview:
Expand All @@ -84,14 +89,15 @@ SPEC CHECKSUMS:
gradient_like_css: 5bf90b38d326b3883145898d762735ca07d17991
keyboard_utils: ab24bc711be9e91a5937c20489056b8dd650fecc
package_info_plus: fd030dabf36271f146f1f3beacd48f564b0f17f7
path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9
path_provider_foundation: eaf5b3e458fc0e5fbb9940fb09980e853fe058b8
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
shared_preferences_foundation: e2dae3258e06f44cc55f49d42024fd8dd03c590c
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
sqflite: 31f7eba61e3074736dff8807a9b41581e4f7f15a
voltron: 573e6755e966a450ea768ab1074d237ad0f41d82
voltron_screen_info: 3f0614af8cdf6aab0b174854a2c8a29fb58316d5
webview_cookie_manager: eaf920722b493bd0f7611b5484771ca53fed03f7
webview_flutter_wkwebview: 2e2d318f21a5e036e2c3f26171342e95908bd60a

PODFILE CHECKSUM: b4c93064582ae64fa0d6a91b4d9b0c383edd9a76
PODFILE CHECKSUM: 9c6f6e76df8eb7d6e4cc1dbb5dae28135d6b4305

COCOAPODS: 1.11.3
COCOAPODS: 1.12.1
2 changes: 2 additions & 0 deletions framework/voltron/example/lib/base_voltron_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class _BaseVoltronPageState extends State<BaseVoltronPage> {
initParams.coreJSAssetsPath = _coreBundle;
initParams.codeCacheTag = "common";
}
// 这里可以不传,默认就是flutterApp,如果是使用flutter module,建议这里使用flutterModule以获取更快的启动速度
initParams.integratedMode = IntegratedMode.flutterApp;
initParams.providers = [
MyAPIProvider(),
];
Expand Down
8 changes: 8 additions & 0 deletions framework/voltron/lib/engine/engine_define.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ enum EngineMode {
singleThread,
}

// IntegratedMode 集成模式
// flutterApp 如果开发的是flutter app,推荐这种方式
// flutterModule 如果开发的是native app + flutter module,推荐这种方式,这种模式下会通过method channel获取屏幕参数,更快
enum IntegratedMode {
flutterApp,
flutterModule,
}

/// 引擎初始化过程中的错误码,对于Voltron sdk开发者调查Voltron sdk的使用者在使用过程中遇到的问题,很必须。
enum EngineInitStatus {
ok, // 初始化过程,一切正常
Expand Down
Loading

0 comments on commit 25859aa

Please sign in to comment.