sysgears / apollo-universal-starter-kit

Apollo Universal Starter Kit is a SEO-friendly, fully-configured, modular starter application that helps developers to streamline web, server, and mobile development with cutting-edge technologies and ultimate code reuse.
https://apollokit.org
MIT License
1.68k stars 324 forks source link

Plist.Info/AndroidManifest.xml #526

Closed fusionbeam closed 7 years ago

fusionbeam commented 7 years ago

Loving your starter-kit so far. What one should do if a component requires some iOS/Android specific project settings. ? (I.e. I am using a camera component that requires some configurations to be put in Plist.Info/AndroidManifest.xml.)

larixer commented 7 years ago

@fusionbeam The kit uses Expo. So you can refer to Expo docs to find out what customization it supports: https://docs.expo.io/versions/latest/sdk/camera.html If this doesn't cover your needs, you should eject from Expo to ExpoKit by executing: yarn exp detach https://docs.expo.io/versions/latest/guides/expokit.html Theoretically this should work, but in practice we haven't tested how good it works now.

fusionbeam commented 7 years ago

thank you.

fusionbeam commented 7 years ago

I've tried to add Expo's camera into the project. Created a client module. The moment I import Expo from 'expo' it complains

^^^^^^

SyntaxError: Unexpected token import

Am I missing something again?

larixer commented 7 years ago

@fusionbeam Well, you should not do it from the component that is included also for Web, since Expo is only available on mobile platforms. What file did you modify / add?

fusionbeam commented 7 years ago

All I did was this inside the generated mobile component container:

import React from 'react';
import Expo from 'expo';
import { graphql, compose } from 'react-apollo';

import CameraScreenView from '../components/CameraScreenView';

class CameraScreeen extends React.Component {

    componentDidMount() {
        Expo.FileSystem.makeDirectoryAsync(Expo.FileSystem.documentDirectory + 'photos').catch(e => {
            console.log(e, 'Directory exists');
        });
    }

  render() {
    return <CameraScreenView {...this.props} />;
  }
}

const CameraWithApollo = compose()(CameraScreeen);

export default CameraWithApollo;
larixer commented 7 years ago

@fusionbeam Yes, but this is critical on what platforms this component is built. It should be built only on mobile platforms, not on Web

fusionbeam commented 7 years ago

I see. how do I reduce a newly created component scope to mobile only? I've used cli addmodule camera client

larixer commented 7 years ago

@fusionbeam How this file is named and where from which file do you import it?

larixer commented 7 years ago

@fusionbeam I think addmodule cli cannot deal with this properly. Check out the code in src/client/modules/counter, see that it has mobile-only index.jsx and web-only index.web.jsx in the root of counter folder. You need to do the same for your component.

fusionbeam commented 7 years ago

import CameraScreen from './containers/CameraScreen'; it is imported in both index.jsx and index.web.jsx. can i delete the index.web.jsx? or shall i create a dummy component for the web

larixer commented 7 years ago

@fusionbeam Create dummy component for index.web.jsx, if you delete it, index.jsx will be used on ALL platforms

fusionbeam commented 7 years ago

got it. thanks again.

fusionbeam commented 7 years ago

it is compiling fine now, but the view is unable to access the component's state. (a variable inside the component class). I'm guessing it has to do with the ApolloClient wrapper ... Is there an example in the starter kit for a component that doesn't use Apollo?

const CameraScreenView = () => {
    return (
        <View style={styles.container}>
          <View style={styles.element}>
            <Camera
                ref={ref => {
                    this.camera = ref;
                }}
                style={{
                    flex: 1
                }}
                type={this.state.type}
                flashMode={this.state.flash}
                autoFocus={this.state.autoFocus}
                zoom={this.state.zoom}
                whiteBalance={this.state.whiteBalance}
                ratio={this.state.ratio}
                focusDepth={this.state.depth}
            >
...
larixer commented 7 years ago

@fusionbeam I have a question looking at this code, how are you going to access state if your component is stateless? If you are going to work with state, you should have stateful component: class CameraScrennView extends React.Component {

fusionbeam commented 7 years ago

That was the component view. The component container is

class CameraScreeen extends React.Component {

    state = {
        flash: 'off',
        zoom: 0,
        autoFocus: 'on',
        depth: 0,
        type: 'back',
        whiteBalance: 'auto',
        ratio: '16:9',
        ratios: [],
        photoId: 1,
        showGallery: false,
        photos: []
    };

    componentDidMount() {
        Expo.FileSystem.makeDirectoryAsync(Expo.FileSystem.documentDirectory + 'photos').catch(e => {
            console.log(e, 'Directory exists');
        });
    }
.... 
fusionbeam commented 7 years ago

never mind. i've figured it out. thanks a lot for your time and patience.