Skip to content

Commit

Permalink
refactor: tickets sdk embedded and modal
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielOS7-TM committed Jul 22, 2024
1 parent 2f17e3f commit 1902d9d
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 66 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,17 @@ Example:

```typescript

import { TicketsSdk } from 'react-native-ticketmaster-ignite';
import { TicketsSdkModal } from 'react-native-ticketmaster-ignite';

const [showTicketsSdk, setShowTicketsSdk] = useState(false);

return (
<TicketsSdkModal
showTicketsModal={showTicketsSdk}
setShowTicketsModal={setShowTicketsSdk}
/>
);

<View>
<TicketsSdk />
</View>
```

#### TicketsSdkEmbeddedIos (embedded tickets for ios)
Expand All @@ -257,9 +263,7 @@ Example:

import { TicketsSdkEmbeddedIos } from 'react-native-ticketmaster-ignite';

<View>
<TicketsSdkEmbeddedIos />
</View>
return <TicketsSdkEmbeddedIos style={{ flex: 1 }} />;
```

#### TicketsSdkEmbeddedAndroid (embedded tickets for android)
Expand All @@ -270,9 +274,7 @@ Example:

import { TicketsSdkEmbeddedAndroid } from 'react-native-ticketmaster-ignite';

<View>
<TicketsSdkEmbeddedAndroid />
</View>
return <TicketsSdkEmbeddedAndroid />;
```

#### RetailSDK
Expand Down
67 changes: 31 additions & 36 deletions example/src/screens/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from 'react-native';
import {
RetailSDK,
TicketsSdk,
TicketsSdkModal,
useIgnite,
} from 'react-native-ticketmaster-ignite';
import Config from 'react-native-config';
Expand All @@ -30,28 +30,6 @@ const Home = () => {
} = useIgnite();

const DATA = [
{
header: 'Retail SDK',
data: [
{
title: 'Show Retail PrePurchase Venue',
platforms: ['android', 'ios'],
onPress: () => onShowPrePurchaseVenue(),
first: true,
},
{
title: 'Show Retail PrePurchase Attraction',
platforms: ['android', 'ios'],
onPress: () => onShowPrePurchaseAttraction(),
},
{
title: 'Show Retail Purchase',
platforms: ['android', 'ios'],
onPress: () => onShowPurchase(),
last: true,
},
],
},
{
header: 'Accounts SDK',
data: [
Expand Down Expand Up @@ -89,6 +67,28 @@ const Home = () => {
},
],
},
{
header: 'Retail SDK',
data: [
{
title: 'Show Retail PrePurchase Venue',
platforms: ['android', 'ios'],
onPress: () => onShowPrePurchaseVenue(),
first: true,
},
{
title: 'Show Retail PrePurchase Attraction',
platforms: ['android', 'ios'],
onPress: () => onShowPrePurchaseAttraction(),
},
{
title: 'Show Retail Purchase',
platforms: ['android', 'ios'],
onPress: () => onShowPurchase(),
last: true,
},
],
},
{
header: 'Tickets SDK',
data: [
Expand All @@ -103,13 +103,6 @@ const Home = () => {
},
];

const onShowTicketsSDK = () => {
setShowTicketsSdk(true);
setTimeout(() => {
setShowTicketsSdk(false);
}, 500);
};

const onShowPurchase = async () => {
try {
await RetailSDK.presentPurchase(Config.DEMO_EVENT_ID);
Expand Down Expand Up @@ -185,6 +178,10 @@ const Home = () => {
}
};

const onShowTicketsSDK = () => {
setShowTicketsSdk(true);
};

return (
<>
{!!isLoggingIn && (
Expand Down Expand Up @@ -234,12 +231,10 @@ const Home = () => {
)}
contentContainerStyle={styles.listPadding}
/>

{showTicketsSdk && (
<View>
<TicketsSdk />
</View>
)}
<TicketsSdkModal
showTicketsModal={showTicketsSdk}
setShowTicketsModal={setShowTicketsSdk}
/>
</>
);
};
Expand Down
12 changes: 2 additions & 10 deletions example/src/screens/MyEvents.ios.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import React, { useEffect, useState } from 'react';
import React from 'react';
import { TicketsSdkEmbeddedIos } from 'react-native-ticketmaster-ignite';

const MyEvents = () => {
const [initialFocus, setInitialFocus] = useState(true);

useEffect(() => {
// Initially, the altered Bottom Tabs View frame height is not available to Native code on iOS, this becomes available after a rerender.
// If needed an additional delay can be used before setting to false
setInitialFocus(false);
}, []);

return <>{!initialFocus && <TicketsSdkEmbeddedIos style={{ flex: 1 }} />}</>;
return <TicketsSdkEmbeddedIos style={{ flex: 1 }} />;

Check warning on line 5 in example/src/screens/MyEvents.ios.tsx

View workflow job for this annotation

GitHub Actions / lint

Inline style: { flex: 1 }
};

export default MyEvents;
3 changes: 0 additions & 3 deletions src/TicketsSdk.tsx

This file was deleted.

31 changes: 26 additions & 5 deletions src/TicketsSdkEmbeddedIos.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import React, { useEffect, useState } from 'react';
import { ViewStyle } from 'react-native';
import { requireNativeComponent, ViewProps } from 'react-native';

interface RNTTicketsSdkEmbeddedViewProps extends ViewProps {
style: Record<string, any>;
style: ViewStyle;
}

export const TicketsSdkEmbeddedIos =
requireNativeComponent<RNTTicketsSdkEmbeddedViewProps>(
'RNTTicketsSdkEmbeddedView'
);
type TicketsSdkEmbeddedIosProps = {
style?: ViewStyle;
renderTimeDelay?: number | undefined;
};

const TicketsSdk = requireNativeComponent<RNTTicketsSdkEmbeddedViewProps>(
'RNTTicketsSdkEmbeddedView'
);

export const TicketsSdkEmbeddedIos = ({
style,
renderTimeDelay,
}: TicketsSdkEmbeddedIosProps) => {
const [initialFocus, setInitialFocus] = useState(true);

useEffect(() => {
// Initially, the altered Bottom Tabs View frame height is not available to Native code on iOS, this becomes available after a rerender.
// If needed an additional delay can be used before setting to false
setTimeout(() => setInitialFocus(false), renderTimeDelay || 0);
}, [renderTimeDelay]);

return <>{!initialFocus && <TicketsSdk style={style || { flex: 1 }} />}</>;

Check warning on line 30 in src/TicketsSdkEmbeddedIos.tsx

View workflow job for this annotation

GitHub Actions / lint

Inline style: { flex: 1 }
};
31 changes: 31 additions & 0 deletions src/TicketsSdkModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { useEffect } from 'react';
import { requireNativeComponent, View } from 'react-native';

const TicketsSdk = requireNativeComponent('RNTTicketsSdkView');

type TicketsSdkModalProps = {
showTicketsModal: boolean;
setShowTicketsModal: (arg0: boolean) => void;
};

export const TicketsSdkModal = ({
showTicketsModal,
setShowTicketsModal,
}: TicketsSdkModalProps) => {
useEffect(() => {
setShowTicketsModal(showTicketsModal);
setTimeout(() => {
setShowTicketsModal(false);
}, 500);
}, [showTicketsModal, setShowTicketsModal]);

return (
<>
{showTicketsModal && (
<View>
<TicketsSdk />
</View>
)}
</>
);
};
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountsSDK } from './AccountsSdk';
import { TicketsSdk } from './TicketsSdk';
import { TicketsSdkModal } from './TicketsSdkModal';
import { TicketsSdkEmbeddedIos } from './TicketsSdkEmbeddedIos';
import { TicketsSdkEmbeddedAndroid } from './TicketsSdkEmbeddedAndroid';
import { RetailSDK } from './RetailSdk';
Expand All @@ -8,7 +8,7 @@ import { useIgnite } from './useIgnite';

export {
AccountsSDK,
TicketsSdk, // Tickets SDK modal is only available for iOS
TicketsSdkModal, // Tickets SDK modal is only available for iOS
TicketsSdkEmbeddedIos,
TicketsSdkEmbeddedAndroid,
RetailSDK,
Expand Down

0 comments on commit 1902d9d

Please sign in to comment.