Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into 3.0_doc
Browse files Browse the repository at this point in the history
  • Loading branch information
zealotchen0 committed Jun 19, 2024
2 parents 2025658 + 473cf27 commit a22bbed
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 91 deletions.
3 changes: 3 additions & 0 deletions docs/development/android-3.0-upgrade-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
}
```

7. HippyDeviceAdapter中reviseDimensionIfNeed接口参数调整 <br>
由于HippyRootView不再监听onSystemUiVisibilityChange消息,移除shouldUseScreenDisplay和systemUiVisibilityChanged两个无效参数。

</br>

# 新增特性
Expand Down
18 changes: 18 additions & 0 deletions docs/development/react-vue-3.0-upgrade-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@

3. hippy-react animation 事件监听不再支持 onRNfqbAnimationXX 兼容写法,统一用 onHippyAnimationXX 或者 onAnimationXX

4. hippy-react 初始化动画对象(new Animation),需要在根节点渲染之后,否则会因为 Dom Manager未创建提示报错
hippy-vue/hippy-vue-next 初始化动画对象(new Animation),需要在 Vue.start 回调之后,否则会因为 Dom Manager未创建提示报错

5. hippy-react/hippy-vue/hippy-vue-next 如果使用了颜色属性的渐变动画,需要显示指定 color 单位,添加 valueType:'color' 字段,例如:

``` javascript
animation: new Animation({
startValue: 'red',
toValue: 'yellow',
valueType: 'color', // 颜色动画需显式指定color单位
duration: 1000,
delay: 0,
mode: 'timing',
timingFunction: 'linear',
}),
```


# 验证关注点

一、Hippy 3.0 前端架构升级主要有如下改动点:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,26 +269,25 @@ public void onSizeChanged(int rootId, int w, int h, int ow, int oh) {
}

@Override
public void updateDimension(int width, int height, boolean shouldUseScreenDisplay,
boolean systemUiVisibilityChanged) {
public void updateDimension(int width, int height) {
if (mEngineContext == null) {
return;
}
Context context = mEngineContext.getGlobalConfigs().getContext();
HippyMap dimensionMap = DimensionsUtil
.getDimensions(width, height, context, shouldUseScreenDisplay);
.getDimensions(width, height, context);
int dimensionW = 0;
int dimensionH = 0;
if (dimensionMap != null) {
HippyMap windowMap = dimensionMap.getMap("windowPhysicalPixels");
dimensionW = windowMap.getInt("width");
dimensionH = windowMap.getInt("height");
LogUtils.i(TAG, "updateDimension: " + dimensionMap);
}
if (height < 0 || dimensionW == dimensionH) {
HippyDeviceAdapter deviceAdapter = mEngineContext.getGlobalConfigs().getDeviceAdapter();
if (deviceAdapter != null) {
deviceAdapter.reviseDimensionIfNeed(context, dimensionMap, shouldUseScreenDisplay,
systemUiVisibilityChanged);
deviceAdapter.reviseDimensionIfNeed(context, dimensionMap);
}
}
DimensionsUtil.convertDimensionsToDp(dimensionMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.tencent.mtt.hippy.adapter.device;

import android.content.Context;
Expand All @@ -24,8 +25,7 @@ public class DefaultDeviceAdapter implements HippyDeviceAdapter {

@SuppressWarnings("unused")
@Override
public void reviseDimensionIfNeed(Context context, HippyMap dimensionMap,
boolean shouldUseScreenDisplay, boolean systemUiVisibilityChanged) {
public void reviseDimensionIfNeed(Context context, HippyMap dimensionMap) {
// Default do nothing here
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@
public interface HippyDeviceAdapter {

@SuppressWarnings({"EmptyMethod", "deprecation"})
void reviseDimensionIfNeed(Context context, HippyMap dimensionMap, boolean shouldUseScreenDisplay,
boolean systemUiVisibilityChanged);
void reviseDimensionIfNeed(Context context, HippyMap dimensionMap);
}
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,12 @@ String getGlobalConfigs() {
assert (context != null);

HippyMap globalParams = new HippyMap();
HippyMap dimensionMap = DimensionsUtil.getDimensions(-1, -1, context, false);
HippyMap dimensionMap = DimensionsUtil.getDimensions(-1, -1, context);

if (mContext.getGlobalConfigs() != null
&& mContext.getGlobalConfigs().getDeviceAdapter() != null) {
mContext.getGlobalConfigs().getDeviceAdapter()
.reviseDimensionIfNeed(context, dimensionMap, false,
false);
.reviseDimensionIfNeed(context, dimensionMap);
}
DimensionsUtil.convertDimensionsToDp(dimensionMap);
globalParams.pushMap("Dimensions", dimensionMap);
Expand Down
23 changes: 21 additions & 2 deletions framework/ios/base/bridge/HippyBridgeDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,29 @@
*/

@class HippyBridge;

#import "HippyInvalidating.h"

@protocol HippyBridgeDelegate <NSObject>

/// An Interceptor protocol for gesture events.
@protocol HippyTouchEventInterceptorProtocol <NSObject>

@optional

/// A centralized handler for event sending,
/// which hippy calls before sending events to the JS side.
///
/// This method is convenient for external data reporting of hippy gesture events
/// - Parameters:
/// - eventName: name of event
/// - point: point in hippyRootView
/// - view: target view
- (void)willSendGestureEvent:(NSString *)eventName withPagePoint:(CGPoint)point toView:(UIView *)view;

@end


/// Delegate of HippyBridge
@protocol HippyBridgeDelegate <NSObject, HippyTouchEventInterceptorProtocol>

@optional

Expand Down
37 changes: 25 additions & 12 deletions framework/ios/base/executors/HippyJSExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@
@interface HippyJSExecutor () {
// Set at setUp time:
id<HippyContextWrapper> _contextWrapper;
NSMutableArray<dispatch_block_t> *_pendingCalls;
__weak HippyBridge *_bridge;
#ifdef JS_JSC
BOOL _isInspectable;
#endif //JS_JSC
}

@property(readwrite, assign) BOOL ready;
/// Whether JSExecutor has done setup.
@property (nonatomic, assign) BOOL ready;
/// Pending blocks to be executed on JS queue.
@property (nonatomic, strong) NSMutableArray<dispatch_block_t> *pendingCalls;;

@end

Expand Down Expand Up @@ -211,12 +213,19 @@ - (void)setup {
strongSelf.contextCreatedBlock(strongSelf->_contextWrapper);
}
scope->SyncInitialize();
strongSelf.ready = YES;
NSArray<dispatch_block_t> *pendingCalls = [strongSelf->_pendingCalls copy];

// execute pending blocks
NSArray<dispatch_block_t> *pendingCalls;
@synchronized (strongSelf) {
strongSelf.ready = YES;
pendingCalls = [strongSelf.pendingCalls copy];
[strongSelf.pendingCalls removeAllObjects];
}
[pendingCalls enumerateObjectsUsingBlock:^(dispatch_block_t _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[strongSelf executeBlockOnJavaScriptQueue:obj];
}];
[strongSelf->_pendingCalls removeAllObjects];

// performance record
auto entry = scope->GetPerformance()->PerformanceNavigation(hippy::kPerfNavigationHippyInit);
entry->SetHippyJsEngineInitStart(startPoint);
entry->SetHippyJsEngineInitEnd(footstone::TimePoint::SystemNow());
Expand Down Expand Up @@ -245,7 +254,7 @@ - (instancetype)initWithEngineKey:(NSString *)engineKey bridge:(HippyBridge *)br
self.bridge = bridge;

self.ready = NO;
_pendingCalls = [NSMutableArray arrayWithCapacity:4];
self.pendingCalls = [NSMutableArray array];
HippyLogInfo(@"[Hippy_OC_Log][Life_Circle],HippyJSCExecutor Init %p, engineKey:%@", self, engineKey);
}

Expand Down Expand Up @@ -595,9 +604,11 @@ static id executeApplicationScript(NSData *script, NSURL *sourceURL, SharedCtxPt
}

- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block {
if (!self.ready) {
[_pendingCalls addObject:block];
return;
@synchronized (self) {
if (!self.ready) {
[self.pendingCalls addObject:block];
return;
}
}
auto engine = [[HippyJSEnginesMapper defaultInstance] JSEngineResourceForKey:self.enginekey]->GetEngine();
if (engine) {
Expand All @@ -611,9 +622,11 @@ - (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block {
}

- (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block {
if (!self.ready) {
[_pendingCalls addObject:block];
return;
@synchronized (self) {
if (!self.ready) {
[self.pendingCalls addObject:block];
return;
}
}
auto engine = [[HippyJSEnginesMapper defaultInstance] JSEngineResourceForKey:self.enginekey]->GetEngine();
if (engine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ public static int getStatusBarHeight() {
return STATUS_BAR_HEIGHT;
}

public static HippyMap getDimensions(int ww, int wh, Context context,
boolean shouldUseScreenDisplay) {
public static HippyMap getDimensions(int ww, int wh, Context context) {
if (context == null) {
return null;
}
Expand All @@ -191,19 +190,11 @@ public static HippyMap getDimensions(int ww, int wh, Context context,
int navigationBarHeight = getNavigationBarHeight(context);

HippyMap windowDisplayMetricsMap = new HippyMap();
if (shouldUseScreenDisplay) {
windowDisplayMetricsMap.pushDouble("width", ww >= 0 ? ww : screenDisplayMetrics.widthPixels);
windowDisplayMetricsMap.pushDouble("height", wh >= 0 ? wh : screenDisplayMetrics.heightPixels);
windowDisplayMetricsMap.pushDouble("scale", screenDisplayMetrics.density);
windowDisplayMetricsMap.pushDouble("fontScale", screenDisplayMetrics.scaledDensity);
windowDisplayMetricsMap.pushDouble("densityDpi", screenDisplayMetrics.densityDpi);
} else {
windowDisplayMetricsMap.pushDouble("width", ww >= 0 ? ww : windowDisplayMetrics.widthPixels);
windowDisplayMetricsMap.pushDouble("height", wh >= 0 ? wh : windowDisplayMetrics.heightPixels);
windowDisplayMetricsMap.pushDouble("scale", windowDisplayMetrics.density);
windowDisplayMetricsMap.pushDouble("fontScale", windowDisplayMetrics.scaledDensity);
windowDisplayMetricsMap.pushDouble("densityDpi", windowDisplayMetrics.densityDpi);
}
windowDisplayMetricsMap.pushDouble("width", ww >= 0 ? ww : windowDisplayMetrics.widthPixels);
windowDisplayMetricsMap.pushDouble("height", wh >= 0 ? wh : windowDisplayMetrics.heightPixels);
windowDisplayMetricsMap.pushDouble("scale", windowDisplayMetrics.density);
windowDisplayMetricsMap.pushDouble("fontScale", windowDisplayMetrics.scaledDensity);
windowDisplayMetricsMap.pushDouble("densityDpi", windowDisplayMetrics.densityDpi);
windowDisplayMetricsMap.pushDouble("statusBarHeight", statusBarHeight);
windowDisplayMetricsMap.pushDouble("navigationBarHeight", navigationBarHeight);
dimensionMap.pushMap("windowPhysicalPixels", windowDisplayMetricsMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public HippyRootView(Context context, int instanceId, int rootId) {
setTag(tagMap);
if (rootId != SCREEN_SNAPSHOT_ROOT_ID) {
getViewTreeObserver().addOnGlobalLayoutListener(getGlobalLayoutListener());
setOnSystemUiVisibilityChangeListener(getGlobalLayoutListener());
}
}

Expand Down Expand Up @@ -89,7 +88,7 @@ protected void onSizeChanged(int w, int h, int ow, int oh) {
super.onSizeChanged(w, h, ow, oh);
NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(getContext());
if ((w != ow || h != oh) && nativeRenderer != null) {
nativeRenderer.updateDimension(w, h, false, false);
nativeRenderer.updateDimension(w, h);
nativeRenderer.onSizeChanged(getId(), w, h, ow, oh);
}
}
Expand Down Expand Up @@ -122,44 +121,29 @@ private GlobalLayoutListener getGlobalLayoutListener() {
return mGlobalLayoutListener;
}

private class GlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener,
OnSystemUiVisibilityChangeListener {
private class GlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener {

private int mOrientation = ORIENTATION_UNDEFINED;

@SuppressWarnings("RedundantIfStatement")
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
checkUpdateDimension(false, true);
} else {
checkUpdateDimension(true, true);
}
}

@Override
public void onGlobalLayout() {
if (getContext() != null) {
int orientation = getContext().getResources().getConfiguration().orientation;
if (orientation != mOrientation) {
mOrientation = orientation;
sendOrientationChangeEvent(mOrientation);
checkUpdateDimension(false, false);
Context context = getContext();
if (context == null) {
return;
}
int orientation = context.getResources().getConfiguration().orientation;
if (orientation != mOrientation) {
mOrientation = orientation;
sendOrientationChangeEvent(mOrientation);
NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(context);
if (nativeRenderer != null) {
nativeRenderer.updateDimension(-1, -1);
}
}
}

private void sendOrientationChangeEvent(int orientation) {
LogUtils.d(TAG, "sendOrientationChangeEvent: orientation=" + orientation);
}

private void checkUpdateDimension(boolean shouldUseScreenDisplay,
boolean systemUiVisibilityChanged) {
NativeRender nativeRenderer = NativeRendererManager.getNativeRenderer(getContext());
if (nativeRenderer != null) {
nativeRenderer.updateDimension(-1, -1, shouldUseScreenDisplay,
systemUiVisibilityChanged);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public interface FrameworkProxy {

void handleNativeException(Exception exception);

void updateDimension(int width, int height, boolean shouldUseScreenDisplay,
boolean systemUiVisibilityChanged);
void updateDimension(int width, int height);

void onSizeChanged(int rootId, int w, int h, int ow, int oh);
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ VirtualNode createVirtualNode(int rootId, int id, int pid, int index, @NonNull S

void onSizeChanged(int rootId, int nodeId, int width, int height, boolean isSync);

void updateDimension(int width, int height, boolean shouldUseScreenDisplay,
boolean systemUiVisibilityChanged);
void updateDimension(int width, int height);

void dispatchEvent(int rootId, int nodeId, @NonNull String eventName,
@Nullable Object params, boolean useCapture, boolean useBubble, EventType eventType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,9 @@ public void onSizeChanged(int rootId, int nodeId, int width, int height, boolean
}

@Override
public void updateDimension(int width, int height, boolean shouldUseScreenDisplay,
boolean systemUiVisibilityChanged) {
public void updateDimension(int width, int height) {
if (mFrameworkProxy != null) {
mFrameworkProxy.updateDimension(width, height, shouldUseScreenDisplay,
systemUiVisibilityChanged);
mFrameworkProxy.updateDimension(width, height);
}
}

Expand Down
6 changes: 0 additions & 6 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1261,8 +1261,6 @@ - (void)addClickEventListenerForView:(UIView *)view onRootNode:(std::weak_ptr<Ro
};
[view setOnClick:eventListener];
}
else {
}
}

- (void)addLongClickEventListenerForView:(UIView *)view onRootNode:(std::weak_ptr<RootNode>)rootNode {
Expand Down Expand Up @@ -1295,8 +1293,6 @@ - (void)addLongClickEventListenerForView:(UIView *)view onRootNode:(std::weak_pt
};
[view setOnLongClick:eventListener];
}
else {
}
}

- (void)addPressEventListenerForType:(const std::string &)type
Expand Down Expand Up @@ -1460,8 +1456,6 @@ - (void)addPropertyEvent:(const std::string &)name
}];
}
}
else {
}
}

#pragma mark -
Expand Down
Loading

0 comments on commit a22bbed

Please sign in to comment.