Skip to content

Instantly share code, notes, and snippets.

@sejas
Last active February 12, 2026 23:36
Show Gist options
  • Select an option

  • Save sejas/9df57fc516602dc4354865d9707d28f8 to your computer and use it in GitHub Desktop.

Select an option

Save sejas/9df57fc516602dc4354865d9707d28f8 to your computer and use it in GitHub Desktop.
Mobile Dev Snippets - React Native & Android (Collection)

Mobile Dev Snippets (React Native & Android)

Tron Custom Command - Navigate to screen (React Native)

Tron Custom Command to Navigate to screen on React Native

      // Navigation
      Tron.onCustomCommand({
        title: 'Choose your NAVIGATION',
        description: 'Insert the screenName where you want to Navigate to.',
        command: 'navigateTo',
        args: [
          {
            name: 'screenName',
            type: 'string',
          },
        ] as CustomCommandArg[],
        handler: ({ screenName }) => {
          if (screenName) {
            console.tron.log('Reactotron navigateTo: ' + screenName)
            RootNavigation.navigate(screenName)
          } else {
            console.tron.log('resetting navigation store')
            RootNavigation.resetRoot({ routes: [] })
          }
        },
      })

Loading React Native MST

Loading React Native MST

preloading-screen.ts

import * as React from "react"
import { observer } from "mobx-react"
import {Register} from "../register"
import {Home} from "../home"
import { MSTUser } from "../../app/models/user"
import { NavigationScreenProps } from "react-navigation"


export interface PreLoadingScreenProps extends NavigationScreenProps<{}> {}

// @inject("mobxstuff")
@observer
export class PreLoading extends React.Component<PreLoadingScreenProps, {}> {
    componentWillMount(){
        MSTUser.onAuthChanges()
    }
    render() {
        return (MSTUser.isLogged)
        ? <Home navigation={this.props.navigation} {...this.props} />
        : <Register navigation={this.props.navigation} {...this.props} />
    }
}

user.ts

import { types, flow } from "mobx-state-tree"
import { firebaseAuth } from "../../services/api/firebase"

export const User = types
.model({
    uuid: "",
    firebaseId: "",
    name: "",
    surname: "",
    selfImage: "",
    passport: "",
    scannedPassport: "",
    token: "",
    pushToken: "",
    isLogged: false
})
.actions(self => ({
        onAuthChanges: () => firebaseAuth.onAuthStateChanged(self.onAuthChangesCallback),
        onAuthChangesCallback(user){
            console.tron.log("onAuthChanges logged:", user)
            if (user) {
                self.isLogged = true
            }
        },
}))

OpenMap Intent (Android)

open-Intent-pasing-string-android.java


        //PASS STRING TO ACTIVITY
        Intent intentToStartDetailActivity = new Intent(context, destinationClass);
        intentToStartDetailActivity.putExtra(Intent.EXTRA_TEXT,"Hellow World!");
        startActivity(intentToStartDetailActivity);

      //GET STRING IN ACTIVITY CHILD
        Intent intentThatStartedThisActivity = getIntent();
        if (intentThatStartedThisActivity.hasExtra(Intent.EXTRA_TEXT)) {
            String textEntered = intentThatStartedThisActivity.getStringExtra(Intent.EXTRA_TEXT);
            detailTV.setText(textEntered);
        }
        
        
        
        

OpenMap-Intent-android.java

    public void onClickOpenAddressButton(View v) {
        String addressString = "plaza mayor 1, Madrid";
        Uri.Builder builder = new Uri.Builder();
        builder.scheme("geo")
                .path("0,0")
                .query(addressString);
        Uri addressUri = builder.build();
        showMap(addressUri);
    }

    private void showMap(Uri geoLocation) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(geoLocation);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    }

OpenWeb-Intent-android.java

    public void onClickOpenWebpageButton(View v) {
        String urlAsString = "https://sejas.es";
        openWebPage(urlAsString);
    }

    private void openWebPage(String url) {
        // Use Uri.parse to parse the String into a Uri
        Uri webpage = Uri.parse(url);

        // Create an Intent with Intent.ACTION_VIEW and the webpage Uri as parameters
        Intent intent = new Intent(Intent.ACTION_VIEW, webpage);

        // Verify that this Intent can be launched and then call startActivity
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment