Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ catalog:
"@rnx-kit/tsconfig": ^2.1.1
"@types/jasmine": 5.1.13
"@types/node": ^22.19.7
"@wdio/appium-service": ^9.23.0
"@wdio/cli": ^9.23.0
"@wdio/appium-service": ^9.24.0
"@wdio/cli": ^9.24.0
"@wdio/globals": ^9.23.0
"@wdio/jasmine-framework": ^9.23.0
"@wdio/jasmine-framework": ^9.24.0
"@wdio/json-reporter": ^9.20.0
"@wdio/local-runner": ^9.23.0
"@wdio/local-runner": ^9.24.0
"@wdio/logger": ^9.18.0
"@wdio/runner": ^9.23.0
"@wdio/spec-reporter": ^9.20.0
"@wdio/runner": ^9.24.0
"@wdio/spec-reporter": ^9.24.0
appium: ^3.1.2
appium-mac2-driver: ^3.2.13
appium-uiautomator2-driver: ^6.7.8
Expand All @@ -43,7 +43,7 @@ catalog:
lage: ^2.14.19
oxc-resolver: ^11.17.0
rimraf: ^6.1.2
webdriverio: ^9.23.0
webdriverio: ^9.24.0

catalogs:
0.73:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
"zx": "^8.2.4"
},
"resolutions": {
"expect-webdriverio": "patch:expect-webdriverio@npm%3A5.6.1#~/.yarn/patches/expect-webdriverio-npm-5.6.1-69666d39e9.patch"
"axios": "^1.13.5",
"expect-webdriverio": "patch:expect-webdriverio@npm%3A5.6.1#~/.yarn/patches/expect-webdriverio-npm-5.6.1-69666d39e9.patch",
"unicorn-magic": "^0.4.0"
},
"engines": {
"node": ">=22.12"
Expand Down
195 changes: 101 additions & 94 deletions packages/experimental/NativeFontMetrics/ios/FRNFontMetrics.m
Original file line number Diff line number Diff line change
@@ -1,136 +1,143 @@
#import "FRNFontMetrics.h"

static NSDictionary<NSString *, NSNumber *> *FRNRecognizedTextStyles() {
static NSDictionary<NSString *, NSNumber *> *styles;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
styles = @{
@"caption1": @(FRNTextStyleCaption1),
@"caption2": @(FRNTextStyleCaption2),
@"footnote": @(FRNTextStyleFootnote),
@"subheadline": @(FRNTextStyleSubheadline),
@"callout": @(FRNTextStyleCallout),
@"body": @(FRNTextStyleBody),
@"headline": @(FRNTextStyleHeadline),
@"title3": @(FRNTextStyleTitle3),
@"title2": @(FRNTextStyleTitle2),
@"title1": @(FRNTextStyleTitle1),
@"largeTitle": @(FRNTextStyleLargeTitle),
};
});
return styles;
static NSDictionary<NSString *, NSNumber *> *styles;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
styles = @{
@"caption1" : @(FRNTextStyleCaption1),
@"caption2" : @(FRNTextStyleCaption2),
@"footnote" : @(FRNTextStyleFootnote),
@"subheadline" : @(FRNTextStyleSubheadline),
@"callout" : @(FRNTextStyleCallout),
@"body" : @(FRNTextStyleBody),
@"headline" : @(FRNTextStyleHeadline),
@"title3" : @(FRNTextStyleTitle3),
@"title2" : @(FRNTextStyleTitle2),
@"title1" : @(FRNTextStyleTitle1),
@"largeTitle" : @(FRNTextStyleLargeTitle),
};
});
return styles;
}

@implementation RCTConvert (FRNTextStyle)

RCT_ENUM_CONVERTER(FRNTextStyle, FRNRecognizedTextStyles(), FRNTextStyleUndefined, integerValue)
RCT_ENUM_CONVERTER(FRNTextStyle, FRNRecognizedTextStyles(),
FRNTextStyleUndefined, integerValue)

@end

NS_ASSUME_NONNULL_BEGIN

UIFontMetrics *FRNUIFontMetricsForTextStyle(FRNTextStyle textStyle) {
static NSDictionary<NSNumber *, UIFontTextStyle> *mapping;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
mapping = @{
@(FRNTextStyleCaption2): UIFontTextStyleCaption2,
@(FRNTextStyleCaption1): UIFontTextStyleCaption1,
@(FRNTextStyleFootnote): UIFontTextStyleFootnote,
@(FRNTextStyleSubheadline): UIFontTextStyleSubheadline,
@(FRNTextStyleCallout): UIFontTextStyleCallout,
@(FRNTextStyleBody): UIFontTextStyleBody,
@(FRNTextStyleHeadline): UIFontTextStyleHeadline,
@(FRNTextStyleTitle3): UIFontTextStyleTitle3,
@(FRNTextStyleTitle2): UIFontTextStyleTitle2,
@(FRNTextStyleTitle1): UIFontTextStyleTitle1,
@(FRNTextStyleLargeTitle): UIFontTextStyleLargeTitle,
};
});

UIFontTextStyle uiFontTextStyle = mapping[@(textStyle)] ?: UIFontTextStyleBody; // Default to body if we don't recognize the specified ramp
return [UIFontMetrics metricsForTextStyle:uiFontTextStyle];
static NSDictionary<NSNumber *, UIFontTextStyle> *mapping;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
mapping = @{
@(FRNTextStyleCaption2) : UIFontTextStyleCaption2,
@(FRNTextStyleCaption1) : UIFontTextStyleCaption1,
@(FRNTextStyleFootnote) : UIFontTextStyleFootnote,
@(FRNTextStyleSubheadline) : UIFontTextStyleSubheadline,
@(FRNTextStyleCallout) : UIFontTextStyleCallout,
@(FRNTextStyleBody) : UIFontTextStyleBody,
@(FRNTextStyleHeadline) : UIFontTextStyleHeadline,
@(FRNTextStyleTitle3) : UIFontTextStyleTitle3,
@(FRNTextStyleTitle2) : UIFontTextStyleTitle2,
@(FRNTextStyleTitle1) : UIFontTextStyleTitle1,
@(FRNTextStyleLargeTitle) : UIFontTextStyleLargeTitle,
};
});

UIFontTextStyle uiFontTextStyle =
mapping[@(textStyle)]
?: UIFontTextStyleBody; // Default to body if we don't recognize the
// specified ramp
return [UIFontMetrics metricsForTextStyle:uiFontTextStyle];
}

CGFloat FRNBaseSizeForTextStyle(FRNTextStyle textStyle) {
static NSDictionary<NSNumber *, NSNumber *> *mapping;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Values taken from https://developer.apple.com/design/human-interface-guidelines/foundations/typography/#specifications
mapping = @{
@(FRNTextStyleCaption2): @11,
@(FRNTextStyleCaption1): @12,
@(FRNTextStyleFootnote): @13,
@(FRNTextStyleSubheadline): @15,
@(FRNTextStyleCallout): @16,
@(FRNTextStyleBody): @17,
@(FRNTextStyleHeadline): @17,
@(FRNTextStyleTitle3): @20,
@(FRNTextStyleTitle2): @22,
@(FRNTextStyleTitle1): @28,
@(FRNTextStyleLargeTitle): @34,
};
});

NSNumber *baseSize = mapping[@(textStyle)] ?: @17; // Default to body size if we don't recognize the specified ramp
return CGFLOAT_IS_DOUBLE ? [baseSize doubleValue] : [baseSize floatValue];
static NSDictionary<NSNumber *, NSNumber *> *mapping;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Values taken from
// https://developer.apple.com/design/human-interface-guidelines/typography/#Specifications
mapping = @{
@(FRNTextStyleCaption2) : @11,
@(FRNTextStyleCaption1) : @12,
@(FRNTextStyleFootnote) : @13,
@(FRNTextStyleSubheadline) : @15,
@(FRNTextStyleCallout) : @16,
@(FRNTextStyleBody) : @17,
@(FRNTextStyleHeadline) : @17,
@(FRNTextStyleTitle3) : @20,
@(FRNTextStyleTitle2) : @22,
@(FRNTextStyleTitle1) : @28,
@(FRNTextStyleLargeTitle) : @34,
};
});

NSNumber *baseSize =
mapping[@(textStyle)] ?: @17; // Default to body size if we don't
// recognize the specified ramp
return CGFLOAT_IS_DOUBLE ? [baseSize doubleValue] : [baseSize floatValue];
}

@implementation FRNFontMetrics {
BOOL _hasListeners;
BOOL _hasListeners;
}

+ (BOOL)requiresMainQueueSetup
{
return YES;
+ (BOOL)requiresMainQueueSetup {
return YES;
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(currentScaleFactors)
{
NSMutableDictionary *result = [NSMutableDictionary new];
[FRNRecognizedTextStyles() enumerateKeysAndObjectsUsingBlock:^(NSString * styleString, __unused NSNumber * boxedTextStyle, __unused BOOL * stop) {
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(currentScaleFactors) {
NSMutableDictionary *result = [NSMutableDictionary new];
[FRNRecognizedTextStyles()
enumerateKeysAndObjectsUsingBlock:^(NSString *styleString,
__unused NSNumber *boxedTextStyle,
__unused BOOL *stop) {
result[styleString] = [self scaleFactorForStyle:styleString];
}];
return result;
}];
return result;
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(scaleFactorForStyle:(NSString *)styleString)
{
FRNTextStyle style = [RCTConvert FRNTextStyle:styleString];
UIFontMetrics *fontMetrics = FRNUIFontMetricsForTextStyle(style);
CGFloat baseSize = FRNBaseSizeForTextStyle(style);
CGFloat scaleFactor = [fontMetrics scaledValueForValue:baseSize] / baseSize;
return @(scaleFactor);
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(scaleFactorForStyle
: (NSString *)styleString) {
FRNTextStyle style = [RCTConvert FRNTextStyle:styleString];
UIFontMetrics *fontMetrics = FRNUIFontMetricsForTextStyle(style);
CGFloat baseSize = FRNBaseSizeForTextStyle(style);
CGFloat scaleFactor = [fontMetrics scaledValueForValue:baseSize] / baseSize;
return @(scaleFactor);
}

#pragma mark - RCTEventEmitter

- (NSArray<NSString *> *_Nullable)supportedEvents
{
return @[ @"onFontMetricsChanged" ];
- (NSArray<NSString *> *_Nullable)supportedEvents {
return @[ @"onFontMetricsChanged" ];
}

- (void)startObserving
{
_hasListeners = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onFontMetricsChanged:)
name:UIContentSizeCategoryDidChangeNotification
object:nil];
- (void)startObserving {
_hasListeners = YES;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(onFontMetricsChanged:)
name:UIContentSizeCategoryDidChangeNotification
object:nil];
}

- (void)stopObserving
{
_hasListeners = NO;
[[NSNotificationCenter defaultCenter] removeObserver:self];
- (void)stopObserving {
_hasListeners = NO;
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - Event processing

- (void)onFontMetricsChanged:(NSNotification *)notification {
if (_hasListeners) {
[self sendEventWithName:@"onFontMetricsChanged" body:@{@"newScaleFactors": [self currentScaleFactors]}];
}
if (_hasListeners) {
[self sendEventWithName:@"onFontMetricsChanged"
body:@{@"newScaleFactors" : [self currentScaleFactors]}];
}
}

RCT_EXPORT_MODULE();
Expand Down
2 changes: 1 addition & 1 deletion packages/theming/apple-theme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Some heuristics followed in this theme:
- For most tokens, we default to prefer the apple system colors, using the FluentUI Apple Palette where it makes sense. These mappings are subject to change as we increment on the design.
- On apple platforms, there tends to not be a "hover" state for components such as Button, so those tokens are mapped to be identical to the rest state (normal state) tokens.
- Similarly, there is not a "checked" state for most components, so those tokens are mapped to the rest state tokens.
- The typography is designed to match the variants provided by the [Apple HIG](https://developer.apple.com/design/human-interface-guidelines/foundations/typography/) for regular and "emphasized". As such, the "Semibold" variants do not always map to the semibold weight, but whatever weight the Apple HIG specifies.
- The typography is designed to match the variants provided by the [Apple HIG](https://developer.apple.com/design/human-interface-guidelines/typography/) for regular and "emphasized". As such, the "Semibold" variants do not always map to the semibold weight, but whatever weight the Apple HIG specifies.
2 changes: 1 addition & 1 deletion packages/theming/apple-theme/src/appleTypography.macos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FontSize, FontSizes, FontWeightValue, Typography, Variants } from

/**
* The Typography is designed to match the styles defined in the Apple HIG:
* https://developer.apple.com/design/human-interface-guidelines/macos/visual-design/typography/
* https://developer.apple.com/design/human-interface-guidelines/typography
* These mappings and variants are subject to change as we moved to a unified cross platform Fluent typography ramp
* Github #598 also tracks pulling these values from a Native Module rather than hardcoding the numbers in JS.
*/
Expand Down
Loading
Loading