I'm running Titanium 3.2.0 and I've created a new Mobile App project with the Alloy template... the thing is the file app.js that all tutorials refer to isn't found. The structure I have include alloy.js under /app and it includes index.js under /app/controllers
Is this a change in 3.2? Where can I find documentation around this?
Thanks!
This is indeed the way Alloy works, there is no app.js.
In alloy.js you can, as the comment of this file suggests, do any initialization for your app or create any global variables/functions that you'd like to make available throughout your app.
You can compare index.js to app.js, it is the entry point to your application (after alloy.js). You can set up your tabGroups or navigationWindows here, the corresponding view is index.xml and the styles are index.tss.
To learn more about the structure of Alloy projects, I would recommend Appcelerators Alloy Framwork docs.
Sample applications for Alloy can be found here.
Related
Im looking everywhere but i cant find anything somebody can explain this question ?
I want to be create my own component library i cant find it
Creating a React Native component library can be a great way to standardize your UI components and speed up your development process. Here are the steps to create a React Native component library:
Set up a new React Native project: Create a new React Native project using the react-native init command. You can choose any name you like for your project.
Create your components: Create the components that you want to include in your library. Each component should be a separate file and should be self-contained.
Export your components: Export each component using the export default statement. This will make the component available for use in other projects.
Create an index file: Create an index.js file in the root of your project. In this file, you can export all of your components as a single object using the export statement.
Publish your library: Publish your library to a package manager like NPM or Yarn. This will make your library available for others to install and use in their projects.
Document your library: Create documentation for your library, including installation instructions, usage examples, and a list of available components. You can use tools like JSDoc or Markdown to create your documentation.
Update your library: Keep your library up-to-date by fixing bugs, adding new features, and improving documentation. You can release new versions of your library to the package manager as needed.
Once you have created your React Native component library, you can use it in any React Native project by installing it from the package manager and importing the components that you need. This can save you time and help you maintain consistency in your UI design across multiple projects.
I have created a react native project and I want to save my UI components on a separate library for reusability. I have created an library mentioned here on the docs but found no proper guidance about package.json, example folder and how does a react-native library works.
Just starting out with trying to build an app with React Native. I decided to use expo + react-navigate + native-base as a baseline, however I am having trouble setting up my project because each documentation seems to be doing things differently.
Specifically, I would like to know where to keep the code for components (e.g. a searchbar) and different screens in react-navigate. The documentation for react-navigate seems to be keeping all screens in the App.js file, but shouldn't I be separating different screens into different .js files in a subfolder? The documentation for native-base completely changes the App.js file so that I have no idea how to implement screens within that. All guides I could find seem to be outdated or not using the expo file structure, so I am having trouble getting the setup to work.
Thanks in advance!
Usually the file structure is somewhat like this:
node_modules
expo
src
screens
components
app.js
package.json
package-lock.json
The src folder will not be there when you initially do expo start.
You will have to make it.
Generally you put the components that you use, in the components directory of the src folder, and the screens in the screens directory. The screens from the screens directory use the components from the components directory.
The app.js file is usually used for the initial screen you want to display on start-up of the app. But also most people make this app.js file into a navigator file where you can import all the navigation screens.
Keep in mind that these rules are just convention, you can customise according to your convenience as well.
I am new to application development with React-native. While creating project with the command react-native init appname the index.js file is also created inside the project folder. Today, I have learned that there is a better way than installing android emulator to test react-native projects which is Expo. To create expo projects I need to create react-native project with create-react-native-app appname command. However, the index.js file is not created while creating project with this way. Even though, I manually created the index.js file, it does not work as it should.
One more question: What is aim of App.js and index.js?
React Native: (react-native init)
A little bit of history. In earlier versions of React Native, separate index.js files were required for iOS and Android. App.js was meant to contain the top level cross platform code for your app. Then index.ios.js and index.android.js would import the cross platform code from App.js and register/link it with the underlying native modules. That allowed you to place top-level cross platform code in one file while placing top-level platform specific code in other files. The index.*.js files were the connectors that wired up the Javascript to native Android or iOS code.
As React Native evolved to remove the platform specific index files, they kept the paradigm of having the top-level Javascript in App.js and using index.js to wire that code to the native modules.
Bottom Line
As a practical matter, don't touch index.js. Make your top-level modifications in App.js.
Expo: (create-react-native-app)
Expo operates a little differently than baseline React Native. You will notice that an Expo project does not contain the ios or android directories. That is because there is no native code associated with an Expo project. All of the native code is contained in the Expo SDK. Since there is no native code to wire up to your Javascript, you do not need an index.js file.
Bottom Line
You should not need an index.js file in an Expo project. If your Expo project is not working, there is likely another problem that needs to be resolved.
I need to create two twin apps with React Native and both apps will be 90% the same they will use some shared components and the styles will be different.
the question is : should i create one react native project and from there to building two apps
and the folder structure will be :
ReactProject
shared
project1
components
project2
components
index.ios.js
index.android.js
and when I want to build one of the apps I will need to change the main component.
or should I create to different React Native projects
and the folder structure will be :
shared
ReactProject1
components
index.ios.js
index.android.js
ReactProject2
components
index.ios.js
index.android.js
I would like to know what is the right approach to do this kind of project
thanks !
This is absolutely a personal preference as stated in comments. One could easily increase the number of structure options beyond 2. Other than that I can share my experience on this.
We build an app, actually 4 (quadruplets), from a single react native project. We choose that way because our apps had to be highly similar. They share same functionality. Furthermore, when one has more than one of these apps installed on their device they can easily switch between apps via deep linking. However they differ on the theme colors, logos, names and backend services to call etc. One of the ways to create multiple apps from a single project is to rename the project. But you can still produce multiple apps while keeping the project name same. Then you need to change some project files accordingly. These files are, for iOS;
Info.plist
project.pbxproj
AppDelegate.m
For Android;
strings.xml
MainActivity.java
MainApplicatoin.java
AndroidManifest.xml
android/build.gradle
app/build.gradle
Actually changing all these files manually is an error-prone and cumbersome action. So that in order to manage these changes we wrote a bash script that converts a base app to the version that we want. Using this approach we can manage 8 apps (quadruplets for iOS and Android) from a single project repo. In the end we are really happy about using React Native which let us build 8 production quality native apps in 3 months without knowing native app development at production level.