Upgrade to Solito 2
Solito 2 is a big step for the React Native + Next.js stack:
- New
solito/image
: Optimized cross-platform imagesnext/image
on Webreact-native-fast-image
on iOS & Android- Expo Go support
- Next.js 13 support
Link
andTextLink
support- Upgraded example monorepos
- Native stack
replace()
support
solito/image
​
Optimized images are one of the most-requested features for cross-platform development.
Solito 2 introduces SolitoImage
, which wraps next/image
on Web and react-native-fast-image
by Dylan Vann on iOS & Android.
tsx
<SolitoImagesrc="/logo.png"height={100}width={200}alt="BeatGig logo"priority/>
tsx
<SolitoImagesrc="/logo.png"height={100}width={200}alt="BeatGig logo"priority/>
You can now use optimized images across platforms with a single API.
A key goal of this component was to bring the next/image
API to native. This meant porting the following features, among others:
src
andsrcSet
supportsizes
property for optimized image sizes. Uses theDimensions
API on native.priority
property- Relative URL paths for images in the Next.js
public
folder - Static files via imported via
import
fill
property for absolute-filled styles- Object fit/resize modes
- React Native
style
prop support across platforms, includingtransform
array, etc. loader
property for custom image loaders- Global image configuration
- Set a global
loader
instead of aloaderFile
- Configure
deviceSizes
- Configure
imageSizes
- Implemented with React Context
- Set a global
unoptimized
prop
For more, see the SolitoImage
docs.
Next.js 13 support​
Solito 2 adds support for Next.js 13.
Links​
TextLink
and Link
now use Next.js' legacyBehavior
prop under the hood. No user changes are required.
Similarly, Next.js' useRouter
hook has been tree shaken on native to avoid runtime errors from Next.js 13 on iOS and Android.
Upgraded example monorepos​
All Solito example monorepos have been upgraded to Next.js 13. The following changes were made:
- Increment Next.js version in
apps/next/package.json
- Change
react-native-reanimated
SWC plugin inapps/next/plugins
- Upgrade
solito
to2.0.0
inpackages/app/package.json
- Upgrade
react
&react-dom
inapps/expo/package.json
to18.2.0
- If you run
expo upgrade
inapps/expo
, this version might get downgraded. If this happens, be sure to manually upgrade to at least18.2.0
.
- If you run
Next.js 13 Upgrade Guide​
While Solito doesn't add any breaking changes to support Next.js 13, Next.js 13 itself does have breaking changes. Please refer to their upgrade guide.
Since the minimum React/React DOM versions are now 18.2.0
, I recommend setting this version as a resolution in your monorepo's root package.json
to avoid version mismatches:
json
{"resolutions": {"react": "18.2.0","react-dom": "18.2.0"}}
json
{"resolutions": {"react": "18.2.0","react-dom": "18.2.0"}}
Native Stack replace()
​
A common point of confusion for Solito users is the router.replace()
function. On Web, it replaces the screen as expected. But on native, it always pushes a new screen, even when using a stack.
This limitation is due to the complexity of determining a user's navigation intentions in a composable way with URLs, especially when dealing with nested navigators.
To solve this feature request, Solito 2 introduces a new nativeBehavior
option in the router.replace()
function:
ts
import { useRouter } from 'solito/router'export function Home() {const router = useRouter()const openArtists = () => {router.replace('/artists', undefined, {experimental: {nativeBehavior: 'stack-replace',isNestedNavigator: true,},})}// ...}
ts
import { useRouter } from 'solito/router'export function Home() {const router = useRouter()const openArtists = () => {router.replace('/artists', undefined, {experimental: {nativeBehavior: 'stack-replace',isNestedNavigator: true,},})}// ...}
By passing nativeBehavior: 'stack-replace'
, you tell Solito to re-write your navigation action with StackActions.replace()
. The isNestedNavigator
property is an important way to indicate to Solito that your stack is nested inside of another navigator, such as tabs. Chances are, this property will always be true
.
You can also use this functionality on the Link
and TextLink
components when replace
is set to true
:
tsx
<Linkhref="/artists"replaceexperimental={{nativeBehavior: 'stack-replace',isNestedNavigator: true,}}/>
tsx
<Linkhref="/artists"replaceexperimental={{nativeBehavior: 'stack-replace',isNestedNavigator: true,}}/>
For now, this feature will live behind the experimental
flag.
Fonts​
Since Solito's custom font loading recommendations are currently quite platform-specific, you should be able to take advantage of Next.js' new @next/font
package without any changes on the native side.
Upgrade guide​
Please follow the steps below to upgrade. This guide will use yarn
.
Upgrade solito in
packages/app
:a.
yarn add solito
Upgrade Next.js in
apps/next
:a.
yarn add next@latest
Add resolutions for
react
andreact-dom
to18.2.0
in your rootpackage.json
:
json
{"resolutions": {"react": "18.2.0","react-dom": "18.2.0"}}
json
{"resolutions": {"react": "18.2.0","react-dom": "18.2.0"}}
See the Next.js 13 upgrade guide for any other changes you need to make.
Upgrade
@react-navigation/native
the newest6.x
version
- The minimum version is
6.0.11
, which exposesLinkingContext
. This is necessary for the newstack-replace
functionality. - This isn't a breaking change, but it will be in a future release.
- If you're using
expo-router
, you may need to set this as a yarn resolution.- First, remove any
@react-navigation
packages from yourpackage.json
s, sinceexpo-router
installs these for you. Next, runyarn
, and finallyyarn why @react-navigation/native
. - If your version is below
6.0.11
, please add a yarn resolution to your rootpackage.json
with a high enough version.
- First, remove any
- Run
yarn
from the root of your monorepo.