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

Hey, I get this issue every time I use TabBarTemplate: #202

Open
EliG-TA opened this issue Jul 23, 2024 · 1 comment
Open

Hey, I get this issue every time I use TabBarTemplate: #202

EliG-TA opened this issue Jul 23, 2024 · 1 comment

Comments

@EliG-TA
Copy link

EliG-TA commented Jul 23, 2024

          Hey, I get this issue every time I use TabBarTemplate:
Your app just crashed. See the error below.
java.lang.IllegalStateException: A title must be set for the tab
  androidx.car.app.model.Tab$Builder.build(Tab.java:210)
  org.birkir.carplay.parser.RCTTabTemplate.parseTab(RCTTabTemplate.kt:41)
  org.birkir.carplay.parser.RCTTabTemplate.parse(RCTTabTemplate.kt:24)
  org.birkir.carplay.parser.RCTTabTemplate.parse(RCTTabTemplate.kt:11)
  org.birkir.carplay.parser.TemplateParser.parse(TemplateParser.kt:30)
  org.birkir.carplay.CarPlayModule.parseTemplate(CarPlayModule.kt:92)
  org.birkir.carplay.CarPlayModule.createScreen(CarPlayModule.kt:292)
  org.birkir.carplay.CarPlayModule.getScreen(CarPlayModule.kt:302)
  org.birkir.carplay.CarPlayModule.setRootTemplate$lambda$2(CarPlayModule.kt:139)
  org.birkir.carplay.CarPlayModule.$r8$lambda$cp18Ybhsx4k_Ka2Moa-_hKNT4FY(Unknown Source:0)
  org.birkir.carplay.CarPlayModule$$ExternalSyntheticLambda6.run(Unknown Source:4)
  android.os.Handler.handleCallback(Handler.java:959)
  android.os.Handler.dispatchMessage(Handler.java:100)
  android.os.Looper.loopOnce(Looper.java:232)
  android.os.Looper.loop(Looper.java:317)
  android.app.ActivityThread.main(ActivityThread.java:8592)
  java.lang.reflect.Method.invoke(Native Method)
  com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

Here is my code:

template.ts

import {
  CarPlay,
  GridTemplate,
  GridButton,
  PointOfInterestTemplate,
  ListTemplate,
  TabBarTemplate,
} from "react-native-carplay";

const template1 = new ListTemplate({
  sections: [
    {
      header: "Test 1",
      items: [{ text: "Hello world 3" }, { text: "Hello world 4" }],
    },
  ],
  title: "TEST1",
  tabTitle: "tada4",
  tabSystemImageName: "tada5",
});
const template2 = new ListTemplate({
  sections: [
    {
      header: "Test 2",
      items: [{ text: "Hello world 3" }, { text: "Hello world 4" }],
    },
  ],
  title: "TEST2",
  tabTitle: "tada1",
  tabSystemImageName: "tada2",
});

const template = new TabBarTemplate({
  templates: [template1, template2],
  tabTitle: "Hello",
  tabSystemImageName: "tada3",
  title: "Template",
  async onTemplateSelect() {},
});

export default template;

App.tsx

import { CarPlay} from "react-native-carplay";
import template from "./carplay/template";

export default function App() {

  const [carPlayConnected, setCarPlayConnected] = useState(CarPlay.connected);

  useEffect(() => {
    CarPlay.registerOnConnect(() => {
      console.log("CarPlay connected");
      CarPlay.setRootTemplate(template);
    });
  });

  useEffect(() => {
    function onConnect() {
      setCarPlayConnected(true);
    }
    function onDisconnect() {
      setCarPlayConnected(false);
    }

    CarPlay.registerOnConnect(onConnect);
    CarPlay.registerOnDisconnect(onDisconnect);

    return () => {
      CarPlay.unregisterOnConnect(onConnect);
      CarPlay.unregisterOnDisconnect(onDisconnect);
    };
  }, [carPlayConnected]);

return (
       // Rest of app components...
  );
  
}

Originally posted by @EliG-TA in #112 (comment)

@OkancanCosar
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants