mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: The `ReactNativeVersion.h` file currently contains a `struct` that holds the React Native version (e.g. `1000.0.0`, as individual ints). For some libraries, we need to conditionally compile out code when using an older React Native version, and that's where library authors usually set compiler flags that hold the react native version - those are usually resolved using a `node require.resolve` script in the Podspec or build.gradle, adding unnecessary complexity. With this PR this becomes obsolete as we now create a `#define` that holds the React Native version directly - so e.g. ```cpp #define REACT_NATIVE_VERSION_MAJOR 0 #define REACT_NATIVE_VERSION_MINOR 67 #define REACT_NATIVE_VERSION_PATCH 1 ``` ..which we can then use to conditionally compile some code in our libraries: ```cpp #include <React/ReactNativeVersion.h> #if REACT_NATIVE_VERSION_MINOR >= 76 // new stuff #else // fallback #endif ``` ## Changelog: [INTERNAL] [ADDED] - Added `REACT_NATIVE_VERSION_*` C++ defines to `ReactNativeVersion.h` <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: https://github.com/facebook/react-native/pull/48813 Test Plan: Just import the header in a library and check if the defines exist! Reviewed By: cortinico Differential Revision: D68441049 Pulled By: javache fbshipit-source-id: 55ac8875e1a3f8ad8b9d12795fed4204e9c5bb77
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
* @format
|
|
* @oncall react_native
|
|
*/
|
|
|
|
/*::
|
|
import type {Version} from '../utils/version-utils';
|
|
*/
|
|
|
|
module.exports = ({version} /*: {version: Version} */) /*: string */ => `/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* ${'@'}generated by scripts/releases/set-version.js
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <string_view>
|
|
|
|
#define REACT_NATIVE_VERSION_MAJOR ${version.major}
|
|
#define REACT_NATIVE_VERSION_MINOR ${version.minor}
|
|
#define REACT_NATIVE_VERSION_PATCH ${version.patch}
|
|
|
|
namespace facebook::react {
|
|
|
|
constexpr struct {
|
|
int32_t Major = ${version.major};
|
|
int32_t Minor = ${version.minor};
|
|
int32_t Patch = ${version.patch};
|
|
std::string_view Prerelease = ${
|
|
version.prerelease != null ? `"${version.prerelease}"` : '""'
|
|
};
|
|
} ReactNativeVersion;
|
|
|
|
} // namespace facebook::react
|
|
`;
|