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

feat(legacy view template): extract view to a separate file #375

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NativeModules, Platform } from 'react-native';

const LINKING_ERROR =
`The package '<%- project.slug -%>' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';

const <%- project.name -%> = NativeModules.<%- project.name %>
? NativeModules.<%- project.name %>
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);

export function multiply(a: number, b: number): Promise<number> {
return <%- project.name -%>.multiply(a, b);
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,2 @@
import { NativeModules, Platform } from 'react-native';
export * from './Native<%- project.name -%>';

const LINKING_ERROR =
`The package '<%- project.slug -%>' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';

const <%- project.name -%> = NativeModules.<%- project.name %>
? NativeModules.<%- project.name %>
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);

export function multiply(a: number, b: number): Promise<number> {
return <%- project.name -%>.multiply(a, b);
}
Original file line number Diff line number Diff line change
@@ -1,26 +1 @@
import {
requireNativeComponent,
UIManager,
Platform,
type ViewStyle,
} from 'react-native';

const LINKING_ERROR =
`The package '<%- project.slug -%>' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';

type <%- project.name -%>Props = {
color: string;
style: ViewStyle;
};

const ComponentName = '<%- project.name -%>View';

export const <%- project.name -%>View =
UIManager.getViewManagerConfig(ComponentName) != null
? requireNativeComponent<<%- project.name -%>Props>(ComponentName)
: () => {
throw new Error(LINKING_ERROR);
};
export * from './<%- project.name -%>View';
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
requireNativeComponent,
UIManager,
Platform,
ViewStyle,
} from 'react-native';

const LINKING_ERROR =
`The package '<%- project.slug -%>' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';

type <%- project.name -%>Props = {
color: string;
style: ViewStyle;
};

const ComponentName = '<%- project.name -%>View';

export const <%- project.name -%>View = UIManager.getViewManagerConfig(ComponentName) != null
? requireNativeComponent<<%- project.name -%>Props>(ComponentName)
: () => {
throw new Error(LINKING_ERROR);
};
Loading