Skip to content

Commit

Permalink
Merge branch 'main' into fix/WaterfallView_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli authored Oct 15, 2024
2 parents 3ee6449 + a803246 commit 39766ee
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
View,
StyleSheet,
Text,
Platform,
} from '@hippy/react';

const STYLE_LOADING = 100;
Expand Down Expand Up @@ -271,8 +270,7 @@ export default class ListExample extends React.Component {
return true;
}}
bounces={true}
// horizontal ListView flag(only Android support)
horizontal={horizontal}
horizontal={horizontal} // horizontal ListView flag
style={[{ backgroundColor: '#ffffff' }, horizontal ? { height: 50 } : { flex: 1 }]}
numberOfRows={dataSource.length}
renderRow={this.getRenderRow}
Expand All @@ -297,33 +295,32 @@ export default class ListExample extends React.Component {
onScroll={this.onScroll}
scrollEventThrottle={1000} // 1s
/>
{Platform.OS === 'android'
? <View
onClick={() => this.changeDirection()}
style={{
position: 'absolute',
right: 20,
bottom: 20,
width: 67,
height: 67,
borderRadius: 30,
boxShadowOpacity: 0.6,
boxShadowRadius: 5,
boxShadowOffsetX: 3,
boxShadowOffsetY: 3,
boxShadowColor: '#4c9afa' }}>
<View style={{
width: 60,
height: 60,
borderRadius: 30,
backgroundColor: '#4c9afa',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}>
<View
onClick={() => this.changeDirection()}
style={{
position: 'absolute',
right: 20,
bottom: 20,
width: 67,
height: 67,
borderRadius: 30,
boxShadowOpacity: 0.6,
boxShadowRadius: 5,
boxShadowOffsetX: 3,
boxShadowOffsetY: 3,
boxShadowColor: '#4c9afa' }}>
<View style={{
width: 60,
height: 60,
borderRadius: 30,
backgroundColor: '#4c9afa',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}>
<Text style={{ color: 'white' }}>切换方向</Text>
</View>
</View> : null}
</View>
</View>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
</li>
</ul>
<div
v-if="Vue.Native.Platform === 'android'"
:style="{
position: 'absolute',
right: 20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
</li>
</ul>
<div
v-if="Platform === 'android'"
:style="{
position: 'absolute',
right: 20,
Expand Down Expand Up @@ -114,7 +113,7 @@
</template>

<script lang="ts">
import { type ListViewEvent, Native } from '@hippy/vue-next';
import { type ListViewEvent } from '@hippy/vue-next';
import { defineComponent, ref, onMounted, type Ref } from '@vue/runtime-core';
const STYLE_LOADING = 100;
Expand Down Expand Up @@ -269,7 +268,6 @@ export default defineComponent({
list,
STYLE_LOADING,
horizontal,
Platform: Native.Platform,
onAppear,
onDelete,
onDisappear,
Expand Down
33 changes: 20 additions & 13 deletions driver/js/packages/hippy-vue-css-loader/src/css-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ let sourceId = 0;
function hippyVueCSSLoader(this: any, source: any) {
const options = getOptions(this);
const parsed = parseCSS(source, { source: sourceId });
const hash = crypto.createHash('shake256', { outputLength: 3 });

const majorNodeVersion = parseInt(process.versions.node.split('.')[0], 10);
const hashType = majorNodeVersion >= 17 ? 'md5' : 'md4';
const hash = crypto.createHash(hashType);
const contentHash = hash.update(source).digest('hex');
sourceId += 1;
const rulesAst = parsed.stylesheet.rules.filter((n: any) => n.type === 'rule').map((n: any) => ([
contentHash,
n.selectors,
// filter comment declaration and empty declaration
n.declarations.filter(dec => dec.type !== 'comment').map((dec: any) => {
const rulesAst = parsed.stylesheet.rules.filter((n: any) => n.type === 'rule').map((n: any) => ({
hash: contentHash,
selectors: n.selectors,

declarations: n.declarations.map((dec: any) => {
let { value } = dec;
const isVariableColor = dec.property?.startsWith('-') && typeof value === 'string'
&& (
Expand All @@ -52,14 +55,18 @@ function hippyVueCSSLoader(this: any, source: any) {
if (dec.property && (dec.property.toLowerCase().indexOf('color') > -1 || isVariableColor)) {
value = translateColor(value);
}
return [dec.property, value];
return {
type: dec.type,
property: dec.property,
value,
};
}),
])).filter(rule => rule[2].length > 0);
const code = `(function(n) {
if (!global[n]) {
global[n] = [];
}));
const code = `(function() {
if (!global['${GLOBAL_STYLE_NAME}']) {
global['${GLOBAL_STYLE_NAME}'] = [];
}
global[n] = global[n].concat(${JSON.stringify(rulesAst)});
global['${GLOBAL_STYLE_NAME}'] = global['${GLOBAL_STYLE_NAME}'].concat(${JSON.stringify(rulesAst)});
if(module.hot) {
module.hot.dispose(() => {
Expand All @@ -70,7 +77,7 @@ function hippyVueCSSLoader(this: any, source: any) {
global['${GLOBAL_DISPOSE_STYLE_NAME}'] = global['${GLOBAL_DISPOSE_STYLE_NAME}'].concat('${contentHash}');
})
}
})('${GLOBAL_STYLE_NAME}')`;
})()`;
return `module.exports=${code}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ import { SelectorsMap } from './css-selectors-match';
import { parseSelector } from './parser';
import { HIPPY_GLOBAL_STYLE_NAME, HIPPY_GLOBAL_DISPOSE_STYLE_NAME } from './';

type Declaration = [property: string, value: string | number];
export type ASTRule = [hash: string, selectors: string[], declarations: Declaration[]];

// style load hook
const beforeLoadStyleHook: Function = (declaration: Function): Function => declaration;

Expand Down Expand Up @@ -73,7 +70,7 @@ function createSimpleSelectorFromAst(ast) {
? new AttributeSelector(ast.property, ast.test, ast.value)
: new AttributeSelector(ast.property);
default:
return new InvalidSelector(new Error('Unknown selector.'));;
return null;
}
}

Expand Down Expand Up @@ -128,23 +125,10 @@ function createSelector(sel) {
* @param beforeLoadStyle
*/
export function fromAstNodes(
astRules: Array<CssAttribute | ASTRule> = [],
astRules: CssAttribute[] = [],
beforeLoadStyle?: Function,
): RuleSet[] {
const rules = astRules.map(rule => {
if (!Array.isArray(rule)) return rule;
const [hash, selectors, declarations] = rule as ASTRule;
return {
hash,
selectors,
declarations: declarations.map(([property, value]) => ({
type: 'declaration',
property,
value,
})),
};
});
return rules.map((rule) => {
return astRules.map((rule) => {
const declarations = rule.declarations
.filter(isDeclaration)
// use default hook when there is no hook passed in
Expand Down
21 changes: 15 additions & 6 deletions framework/ios/base/bridge/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ @interface HippyBridge() {
/// Bundle fetch operation queue (concurrent)
@property (nonatomic, strong) NSOperationQueue *bundleQueue;
/// Record the last execute operation for adding execution dependency.
@property (atomic, strong, nullable) NSOperation *lastExecuteOperation;
@property (nonatomic, strong, nullable) NSOperation *lastExecuteOperation;

/// Cached Dimensions info,will be passed to JS Side.
@property (atomic, strong) NSDictionary *cachedDimensionsInfo;
Expand Down Expand Up @@ -591,13 +591,17 @@ - (void)beginLoadingBundle:(NSURL *)bundleURL
strongSelf.valid, script];
HippyLogError(@"%@", errMsg);
completion(bundleURL, HippyErrorWithMessage(errMsg));
strongSelf.lastExecuteOperation = nil;
@synchronized (self) {
strongSelf.lastExecuteOperation = nil;
}
return;
}
[strongSelf executeJSCode:script sourceURL:bundleURL onCompletion:^(id result, NSError *error) {
HippyLogInfo(@"End executing bundle(%s)",
HP_CSTR_NOT_NULL(bundleURL.absoluteString.lastPathComponent.UTF8String));
strongSelf.lastExecuteOperation = nil;
@synchronized (self) {
strongSelf.lastExecuteOperation = nil;
}
if (completion) {
completion(bundleURL, error);
}
Expand All @@ -624,13 +628,18 @@ - (void)beginLoadingBundle:(NSURL *)bundleURL
// Add dependency, make sure that doing fetch before execute,
// and all execution operations must be queued.
[executeOperation addDependency:fetchOperation];
if (self.lastExecuteOperation) {
[executeOperation addDependency:self.lastExecuteOperation];
@synchronized (self) {
NSOperation *lastOp = self.lastExecuteOperation;
if (lastOp) {
[executeOperation addDependency:lastOp];
}
}

// Enqueue operation
[_bundleQueue addOperations:@[fetchOperation, executeOperation] waitUntilFinished:NO];
self.lastExecuteOperation = executeOperation;
@synchronized (self) {
self.lastExecuteOperation = executeOperation;
}
}

- (void)unloadInstanceForRootView:(NSNumber *)rootTag {
Expand Down
6 changes: 3 additions & 3 deletions modules/footstone/include/footstone/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ bool ShouldCreateLogMessage(LogSeverity severity);

#define HP_CSTR_NOT_NULL( p ) (p ? p : "")

#ifdef DEBUG
#ifdef ENABLE_HIPPY_PERFLOG
// enable perf log output when `ENABLE_HIPPY_PERFLOG` is set

// enable perf log output in debug mode only
#define TDF_PERF_LOG(format, ...) \
footstone::LogMessage::LogWithFormat(__FILE_NAME__, __LINE__, "[HP PERF] " format, \
##__VA_ARGS__)
Expand All @@ -241,4 +241,4 @@ footstone::LogMessage::LogWithFormat(__FILE_NAME__, __LINE__, "[HP PERF] " forma
#define TDF_PERF_LOG(format, ...)
#define TDF_PERF_DO_STMT_AND_LOG(STMT , format, ...)

#endif
#endif /* ENABLE_HIPPY_PERFLOG */
35 changes: 18 additions & 17 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,16 @@ @interface HippyUIManager() {
NSHashTable<id<HippyComponent>> *_componentTransactionListeners;

std::mutex _renderQueueLock;
NSMutableDictionary<NSString *, id> *_viewManagers;
NSArray<Class> *_extraComponents;

NSMutableArray<Class<HippyImageProviderProtocol>> *_imageProviders;
}


/// All managed ViewManagers
@property (atomic, strong) NSMutableDictionary<NSString *, id> *viewManagers;
/// All extra components
@property (atomic, strong) NSArray<Class> *extraComponents;

@end


@implementation HippyUIManager

@synthesize domManager = _domManager;
Expand Down Expand Up @@ -675,36 +675,37 @@ - (void)updateView:(nonnull NSNumber *)componentTag

- (__kindof HippyViewManager *)viewManagerForViewName:(NSString *)viewName {
HippyBridge *strongBridge = self.bridge;
if (!_viewManagers) {
_viewManagers = [NSMutableDictionary dictionary];
if (_extraComponents) {
for (Class cls in _extraComponents) {
if (!self.viewManagers) {
NSMutableDictionary *viewManagers = [NSMutableDictionary dictionary];
if (self.extraComponents) {
for (Class cls in self.extraComponents) {
NSString *viewName = viewNameFromViewManagerClass(cls);
HippyAssert(![_viewManagers objectForKey:viewName],
HippyAssert(![viewManagers objectForKey:viewName],
@"duplicated component %@ for class %@ and %@", viewName,
NSStringFromClass(cls),
NSStringFromClass([_viewManagers objectForKey:viewName]));
[_viewManagers setObject:cls forKey:viewName];
NSStringFromClass([viewManagers objectForKey:viewName]));
[viewManagers setObject:cls forKey:viewName];
}
}
NSArray<Class> *classes = HippyGetViewManagerClasses(strongBridge);
NSMutableDictionary *defaultViewManagerClasses = [NSMutableDictionary dictionaryWithCapacity:[classes count]];
for (Class cls in classes) {
NSString *viewName = viewNameFromViewManagerClass(cls);
if ([_viewManagers objectForKey:viewName]) {
if ([viewManagers objectForKey:viewName]) {
continue;
}
[defaultViewManagerClasses setObject:cls forKey:viewName];
}
[_viewManagers addEntriesFromDictionary:defaultViewManagerClasses];
[viewManagers addEntriesFromDictionary:defaultViewManagerClasses];
self.viewManagers = viewManagers;
}
// Get and instantiate the class
id object = [_viewManagers objectForKey:viewName];
id object = [self.viewManagers objectForKey:viewName];
if (object_isClass(object)) {
HippyViewManager *viewManager = [object new];
viewManager.bridge = strongBridge;
NSAssert([viewManager isKindOfClass:[HippyViewManager class]], @"Must be a HippyViewManager instance");
[_viewManagers setObject:viewManager forKey:viewName];
[self.viewManagers setObject:viewManager forKey:viewName];
object = viewManager;
}
return object;
Expand Down Expand Up @@ -1125,7 +1126,7 @@ - (void)dispatchFunction:(const std::string &)functionName
}

- (void)registerExtraComponent:(NSArray<Class> *)extraComponents {
_extraComponents = extraComponents;
self.extraComponents = extraComponents;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,15 @@ - (void)dirtyText:(BOOL)needToDoLayout {
}

- (void)amendLayoutBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)blocks {
[super amendLayoutBeforeMount:blocks];

if (NativeRenderUpdateLifecycleComputed == _propagationLifecycle) {
return;
if (NativeRenderUpdateLifecycleComputed != _propagationLifecycle) {
//Set needs layout for font change event, etc.
NSNumber *currentTag = self.hippyTag;
[blocks addObject:^(NSDictionary<NSNumber *, UIView *> *viewRegistry, UIView * _Nullable lazyCreatedView) {
UIView *view = lazyCreatedView ?: viewRegistry[currentTag];
[view setNeedsLayout];
}];
}
//Set needs layout for font change event, etc.
NSNumber *currentTag = self.hippyTag;
[blocks addObject:^(NSDictionary<NSNumber *, UIView *> *viewRegistry, UIView * _Nullable lazyCreatedView) {
UIView *view = lazyCreatedView ?: viewRegistry[currentTag];
[view setNeedsLayout];
}];
[super amendLayoutBeforeMount:blocks];
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ - (instancetype)init {
if ((self = [super init])) {
_propagationLifecycle = NativeRenderUpdateLifecycleUninitialized;
_frame = CGRectMake(0, 0, NAN, NAN);
_objectSubviews = [NSMutableArray arrayWithCapacity:8];
_objectSubviews = [NSMutableArray array];
_confirmedLayoutDirection = hippy::Direction::Inherit;
_layoutDirection = hippy::Direction::Inherit;
}
Expand Down

0 comments on commit 39766ee

Please sign in to comment.