Skip to content

Commit

Permalink
Merge pull request #780 from DataDog/dev/support-prev-73-newarch-text…
Browse files Browse the repository at this point in the history
…-props

[FIX] SR: Support < RN 0.73 new arch text properties
  • Loading branch information
marco-saia-datadog authored Jan 20, 2025
2 parents 5c50e9f + 4383cc2 commit 41bed92
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

#if RCT_NEW_ARCH_ENABLED
#import <React-RCTFabric/React/RCTParagraphComponentView.h>
#import <React-RCTFabric/React/RCTConversions.h>
#import <React-Fabric/react/renderer/components/text/ParagraphProps.h>
#import "RCTVersion.h"
namespace rct = facebook::react;
#endif

Expand Down Expand Up @@ -87,11 +89,15 @@ + (NSTextAlignment)getAlignmentFromAttributes:(rct::TextAttributes)textAttribute

+ (UIColor* _Nonnull)getForegroundColorFromAttributes:(rct::TextAttributes)textAttributes {
@try {
#if RCT_VERSION_MINOR > 72
rct::Color color = *textAttributes.foregroundColor;
UIColor* uiColor = (__bridge UIColor*)color.getUIColor().get();
if (uiColor != nil) {
return uiColor;
}
#else
return RCTUIColorFromSharedColor(textAttributes.foregroundColor);
#endif
} @catch (NSException *exception) {}

return RCTTextPropertiesDefaultForegroundColor;
Expand Down
4 changes: 3 additions & 1 deletion packages/react-native-session-replay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"files": [
"src/**",
"lib/**",
"scripts/**",
"android/build.gradle",
"android/detekt.yml",
"android/gradle.properties",
Expand All @@ -40,7 +41,8 @@
"scripts": {
"test": "jest",
"lint": "eslint .",
"prepare": "rm -rf lib && yarn bob build"
"prepare": "rm -rf lib && yarn bob build",
"postinstall": "node scripts/set-ios-rn-version.js"
},
"peerDependencies": {
"react": ">=16.13.1",
Expand Down
47 changes: 47 additions & 0 deletions packages/react-native-session-replay/scripts/set-ios-rn-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const path = require('path');

function getReactNativeVersion() {
try {
// eslint-disable-next-line global-require
return require('react-native/package.json').version;
} catch (error) {
throw new Error(
'Failed to find React Native. Ensure it is installed in your project.'
);
}
}

const rnVersion = getReactNativeVersion();

const outputDir = path.resolve(__dirname, '../ios/Sources');
const outputFile = path.join(outputDir, 'RCTVersion.h');

if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}

const [major, minor, patch] = rnVersion.split('.').map(Number);

const headerContent = `#ifndef RCTVersion_h
#define RCTVersion_h
#define RCT_VERSION_MAJOR ${major || 0}
#define RCT_VERSION_MINOR ${minor || 0}
#define RCT_VERSION_PATCH ${patch || 0}
#endif /* RCTVersion_h */
`;

try {
fs.writeFileSync(outputFile, headerContent, 'utf8');
} catch (error) {
console.error(`Failed to write RCTVersion.h: ${error.message}`);
process.exit(1);
}

0 comments on commit 41bed92

Please sign in to comment.