a0be88fd72
Summary: This PR follows up on https://github.com/facebook/react-native/issues/47182 and https://github.com/facebook/react-native/issues/47348 by adding `force-cache`, the final missing option to align caching controls with the existing behavior on iOS. Local caching behavior remains unchanged: if a cached image is available locally, it will be returned; otherwise, a network request will be made. When an image request is sent over the network, the `force-cache` option sent from the sent fJS side will now use the `okhttp3.CacheControl.FORCE_CACHE` directive. ## Changelog: [ANDROID] [ADDED] - Image `force-cache` caching control option Pull Request resolved: https://github.com/facebook/react-native/pull/47426 Test Plan: New example added to the RNTester under the cache policy examples. Then inspecting that the cache control is set correctly before sending it in the `okhttp3.Request` builder. ```kt FLog.w("ReactNative", "fetching uri: %s, with cacheControl: %s", uri, cacheControlBuilder.build().toString()) // fetching uri: https:...png?cacheBust=force-cache, with cacheControl: no-store, max-stale=2147483647, only-if-cached ``` This case was a bit more tricky to test in terms of e2e as it would involve some caching in the server as well, I'm open to suggestions to make this more complete. Reviewed By: javache Differential Revision: D65490360 Pulled By: Abbondanzo fbshipit-source-id: f807a9793f85caea39c59a370d057b9a1d450a78 |
||
---|---|---|
.. | ||
.maestro | ||
android/app | ||
IntegrationTests | ||
js | ||
NativeComponentExample | ||
NativeCxxModuleExample | ||
NativeModuleExample | ||
RCTTest | ||
RNTester | ||
RNTesterIntegrationTests | ||
RNTesterPods.xcodeproj | ||
RNTesterPods.xcworkspace | ||
RNTesterUnitTests | ||
scripts | ||
.babelrc | ||
.eslintrc | ||
.gitignore | ||
.xcode.env | ||
Gemfile | ||
metro.config.js | ||
package.json | ||
Podfile | ||
Podfile.lock | ||
PrivacyInfo.xcprivacy | ||
react-native.config.js | ||
README.md |
RNTester
The RNTester showcases React Native views and modules.
Running this app
Before running the app, make sure you ran:
git clone https://github.com/facebook/react-native.git
cd react-native
yarn install
Running on iOS
If you are testing non-fabric component, search for and modify the fabric_enabled
flag in RNTester's Podfile.
fabric_enabled = false
Also, if you previously built RNTester with fabric enabled, you might need to clean up the build files and Pods.
# Clean the generated files and folders to clean install RNTester
cd packages/rn-tester
yarn clean-ios
If you are still having a problem after doing the clean up (which can happen if you have built RNTester with older React Native versions where files were generated inside the react-native folder.), the best way might be to clean-install react-native (e.g. remove node_modules and yarn install). If after cleaning up, you are still having issues, you might also want to try RCT_NEW_ARCH_ENABLED=0 bundle exec pod install
to disable the new architecture as it might be conflicting.
Both macOS and Xcode are required.
cd packages/rn-tester
- Install Bundler:
gem install bundler
. We use bundler to install the right version of CocoaPods locally. - Install Bundler and CocoaPods dependencies:
bundle install && bundle exec pod install
oryarn setup-ios-hermes
. In order to use JSC instead of Hermes engine, run:USE_HERMES=0 bundle exec pod install
oryarn setup-ios-jsc
instead. - Open the generated
RNTesterPods.xcworkspace
. This is not checked in, as it is generated by CocoaPods. Do not openRNTesterPods.xcodeproj
directly.
Note for Apple Silicon users
If you own a Mac laptop with Apple Silicon, you need to run some different commands to install and run cocoapods.
sudo arch -x86_64 gem install ffi
: this installs theffi
package to load dynamically-linked libraries.arch -x86_64 pod install
: this runpod install
with the right architecture.
Running on Android
You'll need to have all the prerequisites (SDK, NDK) for Building React Native installed.
You can build and run RN-Tester by using this command from the root of the repo:
yarn android
If you wish to use JSC instead you should invoke:
cd packages/rn-tester
yarn install-android-jsc
yarn start
Note
Building for the first time can take a while.
If you're using a physical device, run adb reverse tcp:8081 tcp:8081
to make sure the device can access Metro.
See Running on Device for additional instructions on using a physical device.
Building from source
Building the app on both iOS and Android means building the React Native framework from source. This way you're running the latest native and JS code the way you see it in your clone of the github repo.
This is different from apps created using react-native init
which have a dependency on a specific version of React Native JS and native code, declared in a package.json
file (and build.gradle
for Android apps).