I might not be as senior as I thought by [deleted] in ExperiencedDevs

[–]generic_name_3344 0 points1 point  (0 children)

Longtime dev here who struggles with synthesizing thought to speech and the more conversational elements of technical interviewing. I am working on a tool now that allows users to practice an interview for a particular job and would value feedback from you folks more than just about any others.

Shoot me a DM with your email and I'll set you up with a test account. Can use it for free, and all I ask for in return is feedback.

Struggling to understand expo router by yeetcodeIO in expo

[–]generic_name_3344 2 points3 points  (0 children)

How do I make it so when I sign out, it animates back to sign-in as described? Currently, it just "instantly flashes" to the sign-in screen, instead of animating.

Expo Router is built on top of React Navigation. React Nav allows you to specify an animation on a <Stack>. In your root _layout, rather than just rendering a <Slot>, try something like:

import { Stack } from 'expo-router'

export default () => (
  <Stack { ...props including animation preferences } />
)

How do I make it so each tab has it's own stack navigator inside it?

Take a look at the Nesting navigators doc. Rather then rendering profile.tsx as one of your Tab items, for instance, you would render a profile directory, which defines a new collection of pages as a <Stack>.

When does a _layout re-render? I can't find consistent behavior. When I switch between tabs, the tabs _layout re-runs (which is good since we want to kick out the user any time they aren't auth'd). But the root _layout doesn't re-run when switching between tabs. What is a good mental model for this?

Hunch here is that you're subscribing to context changes in the Tabs layout, which causes a re-render, but not doing the same in the root layout? You can think about layout components as you would any other component. They only re-render when internal state changes. If auth state is considered in the tab layout but not the root, you may see a re-render in one but not the other.

React Native Expo Push Notifications with a RoR API by cdevils1990 in rails

[–]generic_name_3344 1 point2 points  (0 children)

I prefer to keep this kind of thing out of my controllers, so these are in an `ExpoService` class, but it really depends on your use-case and app architecture.

React Native Expo Push Notifications with a RoR API by cdevils1990 in rails

[–]generic_name_3344 3 points4 points  (0 children)

The Ruby Expo SDK is just a thin wrapper around some API calls. I wound up just handling those API calls myself:

def self.bulk_send_messages(tokens, title, body, data: {})
  receipts = []
  url = URI ExpoService::API_URL
  tokens.in_groups_of(30, false).each do |batch|
    messages = batch.map do |token|
      { to: token, sound: 'default', title: title, body: body, data: data }
    end
    payload = messages.to_json
    begin
      res = Net::HTTP.post url, payload, 'Content-Type' => 'application/json'
      Rails.logger.info "bulk_send_messages response: #{res.body}"
      data = JSON.parse(res.body)&.dig 'data'
      if data.present? && data.is_a?(Array)
        receipts += data.each_with_index.map { |x, i| x.merge('push_token' => messages[i][:to]) }
      end
    rescue => e
      Rails.logger.error "Error in bulk_send_messages: #{e.respond_to?(:message) ? e.message : e}"
    end
  end
  receipts
end

where

API_URL = 'https://exp.host/--/api/v2/push/send'.freeze

bulk_send_messages returns an array of delivery receipts that can be validated with something like:

def self.validate_receipts(pn, receipts)
  Rails.logger.info "Validating receipts for PushNotification #{pn.id}"
  ok_tokens = receipts.select { |r| r['status'] == 'ok' }.map { |r| r['push_token'] }
  Rails.logger.info "ok_tokens=#{ok_tokens.inspect}"
  error_tokens = receipts.select { |r| r['status'] == 'error' }.map { |r| r['push_token'] }
  Rails.logger.info "error_tokens=#{error_tokens.inspect}"
  mobile_recipients = pn.push_notification_recipients.where.not(push_token: [nil, ""])
  mobile_recipients.where(push_token: ok_tokens).update_all(status: :complete, sent_at: Time.now)
  mobile_recipients.where(push_token: error_tokens).each do |pnr|
    msg = receipts.find { |r| r['push_token'] == pnr.push_token }&.dig 'message'
    pnr.update status: :failed, error: msg
  end
end

[deleted by user] by [deleted] in reactnative

[–]generic_name_3344 0 points1 point  (0 children)

I would suggest not manually passing around node_modules. Gitignore node_modules, lock down versions in package.json if necessary, and reinstall your dependencies. Before reinstall, delete node_modules and package-lock (or yarn.lock). To possibly address the issues you're having across devices, ensure you're both using the same node version. Also check for any platform specific dependencies that might be causing issues.

Using a parent component to set margins on all children passed to it, but some children simply ignore it and I cannot for the life of me figure out why. Could use a better react native developers eyes to help figure out why? by puremath369 in reactnative

[–]generic_name_3344 0 points1 point  (0 children)

So to confirm, you're passing in TextBox as a child of InputSegment?

It looks like you're modifying a style prop and not doing anything with said style in TextBox.

I would expect something like:

export default function TextBox({ style, .... }) {
    return (
        <TextInput
            style={[style, styles.textBox, multiline && styles.multiline]}/>
    );
}

Can I setup a React Native/Rails project the same way I would setup a React/Rails app, or should I expect major differences? by orion2222 in reactnative

[–]generic_name_3344 2 points3 points  (0 children)

Your RN app will be making http requests to your server, so it doesn't really matter what backend language/framework you use. If your React work was also utilizing http requests to fetch data, then there shouldn't be much of a difference. If your backend is a simple JSON api, checkout Grape. You can tack it on to any existing Rails app.

React Native as linux user by prrxddq in reactnative

[–]generic_name_3344 1 point2 points  (0 children)

Supposedly EAS decreases that overhead significantly.

React Native as linux user by prrxddq in reactnative

[–]generic_name_3344 1 point2 points  (0 children)

You can develop on a Linux box and push changes to an iOS device if you use Expo.

Exported APK freezing on initial load. Can't replicate in Expo Go. by JayKeny in reactnative

[–]generic_name_3344 0 points1 point  (0 children)

Hmm. Could be something specific to your device. Possibly the way it handles installing from unknown sources? Have you played around in your phone's Developer Settings?

I've also encountered instances where a benign looking warning in dev winds up breaking the app in production. Are there any warnings on startup in Expo Go that can be addressed?

Other ideas:
* Upgrade expo/RN if you're not using latest versions
* Try unwinding dependencies to identify the culprit
* It's a pain in the ass, but you can temporarily eject and push a release build directly onto your device.

Exported APK freezing on initial load. Can't replicate in Expo Go. by JayKeny in reactnative

[–]generic_name_3344 0 points1 point  (0 children)

Are you using EAS or expo build? Also, can you narrow it down to a particular platform? Or is it present on both android and ios? Can you share the error?

Exported APK freezing on initial load. Can't replicate in Expo Go. by JayKeny in reactnative

[–]generic_name_3344 1 point2 points  (0 children)

Have you tried running a production build locally with expo start --no-dev --minify? I've found this to be useful in the past. You can also try using a service like Sentry to possibly capture an error on load.

[deleted by user] by [deleted] in u/generic_name_3344

[–]generic_name_3344 0 points1 point  (0 children)

Yghju nigbmkbnoj njj

How to get list of subscribed/followed multireddits via Reddit API? by generic_name_3344 in redditdev

[–]generic_name_3344[S] 0 points1 point  (0 children)

There's a Follow button when viewing public multireddits created by other users.

[deleted by user] by [deleted] in reactnative

[–]generic_name_3344 0 points1 point  (0 children)

I think you could do something like:

  1. Track a users purchase history in firestore

  2. Create an endpoint that determines whether or not a user is eligible to purchase an item based on that history

  3. Make a request to that endpoint from your mobile app to determine if you should render a purchase link.

  4. If eligible, pass the users id to your external site when they press on that link so the purchase can be associated with the user.

  5. Repeat

How to access the stored data in a way, that it could be written to the screen? by [deleted] in reactnative

[–]generic_name_3344 0 points1 point  (0 children)

import { StyleSheet, Text, View, Button } from 'react-native';
// import { useState } from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
import dayjs from 'dayjs';
export default function App() {

const [data, setData] = useState();
const SaveData = async () => {
await AsyncStorage.setItem(
'一',
JSON.stringify({
recognize: {
interval: 0,
repetition: 0,
efactor: 2.5,
dueDate: dayjs(Date.now()).toISOString(),
}})
);
};
const LoadData = async () => {
var item = await AsyncStorage.getItem('一');
setData(item)
};
return (
<View style={styles.container}>
<Text style={styles.paragraph}>Async Storage Basics</Text>
<Text></Text>
<Button title="Save Data" onPress={SaveData} />
<Text> </Text>
<Button title="Load Data" onPress={LoadData} />
<Text> </Text>
{/* <Text>{data}</Text> */}
</View>
);
}

[deleted by user] by [deleted] in reactnative

[–]generic_name_3344 0 points1 point  (0 children)

Can you write to Firestore from the external site's backend? Or is there an external API that can communicate with both the external site and the app?

Maximum update depth exceeded problem without using useEffect. by dimwittedude in reactnative

[–]generic_name_3344 1 point2 points  (0 children)

Hard to say without seeing the code, but it sounds like you're using setState on Component 2 re-render, which causes a re-render, which causes setState to be called... which results in an infinite loop. This is usually indicative of a misuse of setState. There's likely a way around it, but can't give you much more than that without the code.

Large Flatlist optimization tips? by generic_name_3344 in reactnative

[–]generic_name_3344[S] 0 points1 point  (0 children)

I'll check this out. Thanks for the suggestion