Files
paseo/packages/react-native-enriched-markdown/ios/utils/ENRMParticleOverlayView.m
T
Mohamed Boudra 80c44321cc Move the Markdown engine into the repository and fix two Android list layouts (#10499)
* chore(app): vendor react-native-enriched-markdown with the Paseo patch applied

Copy react-native-enriched-markdown@1.2.0-nightly-20261014-766fc0e67 (upstream
software-mansion/enriched-markdown 766fc0e67) into
packages/react-native-enriched-markdown, with
patches/react-native-enriched-markdown+1.2.0-nightly-20261014-766fc0e67.patch
applied. Nothing else changes in this commit; the package is not a workspace yet.

Reproduce:

  npm pack react-native-enriched-markdown@1.2.0-nightly-20261014-766fc0e67
  tar xzf react-native-enriched-markdown-*.tgz
  mkdir -p t/node_modules && mv package t/node_modules/react-native-enriched-markdown
  (cd t && git init -q && git apply ../patches/react-native-enriched-markdown+*.patch)
  diff -r t/node_modules/react-native-enriched-markdown packages/react-native-enriched-markdown

The diff is empty.

* chore(app): consume react-native-enriched-markdown from its workspace

Make packages/react-native-enriched-markdown a private workspace and point the
app at it, then remove the patch-package patch it replaces.

- package.json: private, version follows the root like every workspace, only the
  postinstall script that downloads tree-sitter grammars. Upstream's
  devDependencies would install a second react-native, so they are gone.
- The package keeps its name, so autolinking, the Gradle project
  :react-native-enriched-markdown, the CocoaPods spec and imports are unchanged.
- Lockfile: drop the nested registry copy under packages/app/node_modules; npm
  links node_modules/react-native-enriched-markdown to the workspace.
- Formatting, lint and knip skip the vendored code. CI routes changes to it
  through the app and browser suites.
- The codegen test checks the vendored package's generated props.
- docs/markdown-renderer.md describes the fork and how to edit it.

* fix(app): keep numbered sub-list markers off their text on Android

From #9964, moved from the package patch into the vendored package.

On Android, a numbered list nested in a bulleted item drew "1." over
the first letters of each item. A nested item's text indent summed the
root list's narrow bullet column with a fixed marginLeft, while its
marker was right-aligned to its own wider "99." column, so the number
landed on the text. iOS already indents from the item's own column.

Backport the Android hunks of upstream enriched-markdown #1015 (size
the number column to the widest marker) and #1023 (nested items start
their text from their own marker column).

test:android now also runs the backported ListRenderingTest and
TaskListInteractionTest suites. docs/markdown-renderer.md lists the
fork's backports, this one and #924, which the removed postinstall
comment used to track.

The vendored tree equals the #9964 patch applied to the pristine
package.

* fix(app): keep Android assistant replies inside their turns

From #10380, moved from the package patch into the vendored package.

On Android, an assistant reply with blockquotes nested inside a list
could overlap its "Worked for ..." footer and the next user message:
the displayed text and the layout measurement applied spans in
different orders, and the list-wide line height inflated the blockquote
spacers when it ran after them.

Use the same span order for Android Markdown measurement and display.
Apply list line height before blockquote spacers so nested quotes keep
their configured padding and the reply fits above the turn footer.

test:android now also runs ListBlockquoteMeasurementTest.

Applied on top of #9964; the two changes share only ListRenderer.kt,
where #10380's import and line-height call sit beside #9964's marker
width code. Every other file equals the #10380 patch applied to the
pristine package.

* chore(app): match the vendored Markdown web block renderer source to its build

The package patch changed lib/module/web/renderers/BlockRenderers.js (the
renderers.codeBlock override and the zoom-in cursor on images) but not
src/web/renderers/BlockRenderers.tsx. The app runs lib, so behavior does
not change. Port both changes into src so src stays the source of lib.
2026-11-23 10:15:43 +07:00

160 lines
5.5 KiB
Objective-C

#import "ENRMParticleOverlayView.h"
#import <QuartzCore/QuartzCore.h>
static const CGFloat kDefaultParticleDensity = 8.0;
static const CGFloat kDefaultParticleSpeed = 20.0;
static const CGFloat kDotImageSize = 6.0;
static const CGFloat kRevealVelocityMultiplier = 10.0;
static const CGFloat kRevealAlphaSpeedMultiplier = 6.0;
static const CGFloat kDot1BirthRateMin = 3.0;
static const CGFloat kDot1BirthRatePerArea = 0.013;
static const CGFloat kDot1Lifetime = 1.6;
static const CGFloat kDot1Velocity = 8.0;
static const CGFloat kDot1Scale = 0.25;
static const CGFloat kDot1AlphaSpeed = -0.25;
static const CGFloat kDot2BirthRateMin = 1.5;
static const CGFloat kDot2BirthRatePerArea = 0.007;
static const CGFloat kDot2Lifetime = 1.2;
static const CGFloat kDot2Velocity = 12.0;
static const CGFloat kDot2Scale = 0.18;
static const CGFloat kDot2AlphaSpeed = -0.3;
static const CGFloat kMaxParticleLifetime = 1.6; // must match the longest lifetime above
static CGImageRef sharedDotCGImage(void)
{
static CGImageRef cgImage;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(NULL, (size_t)kDotImageSize, (size_t)kDotImageSize, 8, 0, space,
kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(space);
CGContextSetRGBFillColor(ctx, 1, 1, 1, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(0, 0, kDotImageSize, kDotImageSize));
cgImage = CGBitmapContextCreateImage(ctx);
CGContextRelease(ctx);
});
return cgImage;
}
@implementation ENRMParticleOverlayView {
CAEmitterLayer *_emitterLayer;
RCTUIColor *_particleColor;
CGFloat _particleDensity;
CGFloat _particleSpeed;
}
- (instancetype)initWithConfig:(StyleConfig *)config charRange:(NSRange)charRange
{
if (self = [super initWithCharRange:charRange]) {
_particleColor = [config spoilerColor];
_particleDensity = [config spoilerParticleDensity];
_particleSpeed = [config spoilerParticleSpeed];
}
return self;
}
#pragma mark - Overrides
- (void)didAttachToSuperview
{
self.layer.backgroundColor = [self resolveBackgroundCGColor];
if (!_emitterLayer) {
[self setupEmitter];
}
}
- (void)didLayoutOverlay
{
if (!_emitterLayer) {
// Emitter creation is deferred when bounds were zero at attach time.
[self setupEmitter];
return;
}
if (!self.revealing) {
_emitterLayer.frame = self.bounds;
_emitterLayer.emitterPosition = CGPointMake(self.bounds.size.width / 2.0, self.bounds.size.height / 2.0);
_emitterLayer.emitterSize = self.bounds.size;
}
}
- (void)prepareRevealAnimation
{
_emitterLayer.birthRate = 0;
for (CAEmitterCell *cell in _emitterLayer.emitterCells) {
NSString *velocityPath = [NSString stringWithFormat:@"emitterCells.%@.velocity", cell.name];
NSString *alphaPath = [NSString stringWithFormat:@"emitterCells.%@.alphaSpeed", cell.name];
[_emitterLayer setValue:@(cell.velocity * kRevealVelocityMultiplier) forKeyPath:velocityPath];
[_emitterLayer setValue:@(cell.alphaSpeed * kRevealAlphaSpeedMultiplier) forKeyPath:alphaPath];
}
}
#pragma mark - Emitter setup
- (CAEmitterCell *)makeParticleCellWithName:(NSString *)name
birthRate:(CGFloat)birthRate
lifetime:(CGFloat)lifetime
velocity:(CGFloat)velocity
scale:(CGFloat)scale
alphaSpeed:(CGFloat)alphaSpeed
{
CAEmitterCell *cell = [CAEmitterCell emitterCell];
cell.name = name;
cell.contents = (__bridge id)sharedDotCGImage();
cell.color = _particleColor.CGColor;
cell.birthRate = birthRate;
cell.lifetime = lifetime;
cell.lifetimeRange = lifetime * 0.3;
cell.velocity = velocity;
cell.velocityRange = velocity * 0.5;
cell.emissionRange = M_PI * 2;
cell.scale = scale;
cell.scaleRange = scale * 0.3;
cell.alphaRange = 0.2;
cell.alphaSpeed = alphaSpeed;
return cell;
}
- (void)setupEmitter
{
CGRect bounds = self.bounds;
if (bounds.size.width <= 0 || bounds.size.height <= 0)
return;
CGFloat area = bounds.size.width * bounds.size.height;
CGFloat densityFactor = _particleDensity / kDefaultParticleDensity;
CGFloat speedFactor = _particleSpeed / kDefaultParticleSpeed;
_emitterLayer = [CAEmitterLayer layer];
_emitterLayer.emitterShape = kCAEmitterLayerRectangle;
_emitterLayer.renderMode = kCAEmitterLayerOldestLast;
_emitterLayer.frame = bounds;
_emitterLayer.emitterPosition = CGPointMake(bounds.size.width / 2.0, bounds.size.height / 2.0);
_emitterLayer.emitterSize = bounds.size;
_emitterLayer.emitterCells = @[
[self makeParticleCellWithName:@"dot1"
birthRate:MAX(kDot1BirthRateMin, area * kDot1BirthRatePerArea * densityFactor)
lifetime:kDot1Lifetime
velocity:kDot1Velocity * speedFactor
scale:kDot1Scale
alphaSpeed:kDot1AlphaSpeed],
[self makeParticleCellWithName:@"dot2"
birthRate:MAX(kDot2BirthRateMin, area * kDot2BirthRatePerArea * densityFactor)
lifetime:kDot2Lifetime
velocity:kDot2Velocity * speedFactor
scale:kDot2Scale
alphaSpeed:kDot2AlphaSpeed],
];
// Backdate the emitter so it appears pre-populated with particles.
_emitterLayer.beginTime = CACurrentMediaTime() - kMaxParticleLifetime;
[self.layer addSublayer:_emitterLayer];
}
@end