Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to React Native 0.76 and Expo 52 #2241

Merged
merged 12 commits into from
Dec 12, 2024
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
4 changes: 0 additions & 4 deletions react-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ phone while hitting a server running on your computer.
Starts the server locally using Expo. You should then be able to see it running on a phone provided you have the above
app downloaded and configured.

Note that React-Native does not fully support the Fetch API when running on mobile and as a result, the Connect
transport does not work properly in that environment. Instead, we create a custom XHR transport for use in that
circumstance.

To update the React Native project, you have to check the
[React Native Upgrade Helper](https://react-native-community.github.io/upgrade-helper/) for guidance.

Expand Down
2 changes: 2 additions & 0 deletions react-native/app.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"expo": {
"sdkVersion": "52.0.0",
"name": "eliza",
"slug": "eliza",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/images/icon.png",
"scheme": "eliza",
"userInterfaceStyle": "automatic",
"newArchEnabled": true,
"splash": {
"image": "./assets/images/splash.png",
"resizeMode": "contain",
Expand Down
197 changes: 0 additions & 197 deletions react-native/app/custom-transport.ts

This file was deleted.

39 changes: 23 additions & 16 deletions react-native/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from "react";
import { fetch, FetchRequestInit } from "expo/fetch";
import {
Button,
Dimensions,
Expand All @@ -8,39 +9,46 @@ import {
TextInput,
View,
} from "react-native";
import { createClient, Code, ConnectError } from "@connectrpc/connect";
import { createXHRGrpcWebTransport } from "./custom-transport";
import { createClient, ConnectError } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-web";
import {
ElizaService,
IntroduceRequestSchema,
} from "../gen/connectrpc/eliza/v1/eliza_pb.js";
// Needed to polyfill TextEncoder/ TextDecoder
import "fast-text-encoding";
import { create } from "@bufbuild/protobuf";
import { polyfills } from "./polyfills";

polyfills();

interface Response {
interface ConvoResponse {
text: string;
sender: "eliza" | "user";
}

function Index() {
const [statement, setStatement] = useState<string>("");
const [introFinished, setIntroFinished] = useState<boolean>(false);
const [responses, setResponses] = useState<Response[]>([
const [responses, setResponses] = useState<ConvoResponse[]>([
{
text: "What is your name?",
sender: "eliza",
},
]);

// Make the Eliza Service client
// Make the Eliza Service client using grpc-web transport.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're actually using the connect transport. Would be great to smoke test both with JSON and binary.

We also need to update README.md.

And https://connectrpc.com/docs/web/supported-browsers-and-frameworks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with binary format also and can confirm all 3 areas work (web, simulator, expo go).

Updated README and also created connectrpc/connectrpc.com#244 for the docs.

const client = createClient(
ElizaService,
createXHRGrpcWebTransport({
createConnectTransport({
baseUrl: "https://demo.connectrpc.com",
// Customize fetch with the Expo fetch implementation
fetch: (input, init) => {
if (typeof input !== "string") {
throw new Error(
"expo/fetch requires the first argument to be a string URL",
);
}
return fetch(
input,
init as unknown as FetchRequestInit,
) as unknown as Promise<Response>;
},
}),
);

Expand All @@ -63,6 +71,9 @@ function Index() {
name: statement,
});

// Note that cancelling streams does not currently work with
// React Native Expo v52.
// See https://github.com/expo/expo/issues/33549 for more context.
let stream = client.introduce(request);
for await (const response of stream) {
setResponses((resps) => [
Expand All @@ -73,11 +84,7 @@ function Index() {
} catch (err) {
let text = "";
if (err instanceof ConnectError) {
if (err.code === Code.Unimplemented) {
text = `Hi, ${statement}. Streaming is not supported in React Native currently.`;
} else {
text = `A Connect error has occurred: ${err.code} - ${err.message}`;
}
text = `A Connect error has occurred: ${err.message}`;
} else {
text = `An error has occurred: ${err}`;
}
Expand Down
35 changes: 0 additions & 35 deletions react-native/app/polyfills.native.ts

This file was deleted.

2 changes: 0 additions & 2 deletions react-native/app/polyfills.ts

This file was deleted.

3 changes: 2 additions & 1 deletion react-native/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
const { getDefaultConfig } = require("@expo/metro-config");
const { mergeConfig } = require("metro-config");

const defaultConfig = getDefaultConfig(__dirname);

Expand Down
Loading
Loading