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

Revert dynamic styles PR #6218

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
216 changes: 0 additions & 216 deletions apps/common-app/src/examples/DynamicStylesExample.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions apps/common-app/src/examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ import WobbleExample from './WobbleExample';
import WorkletExample from './WorkletExample';
import WorkletRuntimeExample from './WorkletRuntimeExample';
import NestedLayoutAnimationConfig from './LayoutAnimations/NestedLayoutAnimationConfig';
import DynamicStylesExample from './DynamicStylesExample';
import WithClampExample from './WithClampExample';
import WorkletFactoryCrash from './WorkletFactoryCrashExample';
import RuntimeTestsExample from './RuntimeTests/RuntimeTestsExample';
Expand Down Expand Up @@ -491,11 +490,6 @@ export const EXAMPLES: Record<string, Example> = {
title: 'Log test',
screen: LogExample,
},
DynamicStylesExample: {
szydlovsky marked this conversation as resolved.
Show resolved Hide resolved
icon: '🧨',
title: 'Dynamically appending/removing styles',
screen: DynamicStylesExample,
},
WorkletFactoryCrash: {
icon: '🏭',
title: 'Worklet factory crash',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ export function hasInlineStyles(style: StyleProps): boolean {

export function getInlineStyle(
style: Record<string, unknown>,
shouldGetInitialStyle: boolean
isFirstRender: boolean
) {
if (shouldGetInitialStyle) {
if (isFirstRender) {
return getInlinePropsUpdate(style);
}
const newStyle: StyleProps = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

import { shallowEqual } from '../hook/utils';
import type { StyleProps } from '../commonTypes';
import { isSharedValue } from '../isSharedValue';
import { isChromeDebugger } from '../PlatformChecker';
Expand All @@ -24,30 +23,23 @@ function dummyListener() {

export class PropsFilter implements IPropsFilter {
private _initialStyle = {};
private _previousProps: React.Component['props'] | null = null;
private _requiresNewInitials = true;

public filterNonAnimatedProps(
component: React.Component<unknown, unknown> & IAnimatedComponentInternal
): Record<string, unknown> {
const inputProps =
component.props as AnimatedComponentProps<InitialComponentProps>;

this._maybePrepareForNewInitials(inputProps);

const props: Record<string, unknown> = {};
for (const key in inputProps) {
const value = inputProps[key];
if (key === 'style') {
const styleProp = inputProps.style;
const styles = flattenArray<StyleProps>(styleProp ?? []);
if (this._requiresNewInitials) {
this._initialStyle = {};
}
const processedStyle: StyleProps = styles.map((style) => {
if (style && style.viewDescriptors) {
// this is how we recognize styles returned by useAnimatedStyle
if (this._requiresNewInitials) {
style.viewsRef?.add(component);
szydlovsky marked this conversation as resolved.
Show resolved Hide resolved
if (component._isFirstRender) {
this._initialStyle = {
...style.initial.value,
...this._initialStyle,
Expand All @@ -56,7 +48,7 @@ export class PropsFilter implements IPropsFilter {
}
return this._initialStyle;
} else if (hasInlineStyles(style)) {
return getInlineStyle(style, this._requiresNewInitials);
return getInlineStyle(style, component._isFirstRender);
} else {
return style;
}
Expand All @@ -70,6 +62,7 @@ export class PropsFilter implements IPropsFilter {
Object.keys(animatedProp.initial.value).forEach((initialValueKey) => {
props[initialValueKey] =
animatedProp.initial?.value[initialValueKey];
animatedProp.viewsRef?.add(component);
szydlovsky marked this conversation as resolved.
Show resolved Hide resolved
});
}
} else if (
Expand All @@ -88,26 +81,13 @@ export class PropsFilter implements IPropsFilter {
props[key] = dummyListener;
}
} else if (isSharedValue(value)) {
if (this._requiresNewInitials) {
if (component._isFirstRender) {
props[key] = value.value;
}
} else if (key !== 'onGestureHandlerStateChange' || !isChromeDebugger()) {
props[key] = value;
}
}
this._requiresNewInitials = false;
return props;
}

private _maybePrepareForNewInitials(
inputProps: AnimatedComponentProps<InitialComponentProps>
) {
if (this._previousProps && inputProps.style) {
this._requiresNewInitials = !shallowEqual(
this._previousProps,
inputProps
);
}
this._previousProps = inputProps;
}
}
Loading