Skip to content

Commit

Permalink
fix: Ads config locking/unlocking rewarded features
Browse files Browse the repository at this point in the history
  • Loading branch information
dariodumlijan committed Mar 19, 2024
1 parent 180714e commit c91f4c6
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 53 deletions.
25 changes: 11 additions & 14 deletions app/components/elements/inputs/TimeSignatureSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { timeSignatureSelectStyle } from '../../../styles/inputs';
import settingsStyle from '../../../styles/settings';
import { SoundKey } from '../../../types';
import useSelectLists from '../../../utils/lists';
import ConditionalAd from '../misc/ConditionalAd';
import type { TimeSignature } from '../../../store/globalStore';
import type { TimeSig } from '../../../utils/lists';

Expand Down Expand Up @@ -109,19 +108,17 @@ function TimeSignatureSelect(props: Props) {
</TouchableOpacity>

{!props.unlockedPro && (
<ConditionalAd>
<TouchableHighlight
style={[settingsStyle.btnRewardScreen, {
marginBottom: 0,
}]}
onPress={props.onRewardedClick}
underlayColor={colors.grayBlue}
>
<Text style={settingsStyle.btnRewardScreenText}>
{t('settings.unlock_advanced')}
</Text>
</TouchableHighlight>
</ConditionalAd>
<TouchableHighlight
style={[settingsStyle.btnRewardScreen, {

Check warning on line 112 in app/components/elements/inputs/TimeSignatureSelect.tsx

View workflow job for this annotation

GitHub Actions / Test

Inline style: { marginBottom: 0 }
marginBottom: 0,
}]}
onPress={props.onRewardedClick}
underlayColor={colors.grayBlue}
>
<Text style={settingsStyle.btnRewardScreenText}>
{t('settings.unlock_advanced')}
</Text>
</TouchableHighlight>
)}
</View>

Expand Down
20 changes: 9 additions & 11 deletions app/components/elements/misc/AdmobBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';
import { View } from 'react-native';
import { BannerAd, BannerAdSize } from 'react-native-google-mobile-ads';
import { isEqual } from 'lodash';
import ConditionalAd from './ConditionalAd';
import { selectors } from '../../../store/globalStore';
import mainStyle from '../../../styles/main';
import { config } from '../../../tokens';
import { isTablet } from '../../../utils';
import { useAppSelector, useLocationInfo } from '../../../utils/hooks';

Expand All @@ -26,16 +26,14 @@ function AdmobBanner() {

return (
<View style={mainStyle.ads}>
{banner && showAds && (
<ConditionalAd>
<BannerAd
unitId={banner}
size={handleBannerSize()}
requestOptions={{
requestNonPersonalizedAdsOnly: !personalisedAds,
}}
/>
</ConditionalAd>
{config.ads && showAds && banner && (
<BannerAd
unitId={banner}
size={handleBannerSize()}
requestOptions={{
requestNonPersonalizedAdsOnly: !personalisedAds,
}}
/>
)}
</View>
);
Expand Down
13 changes: 0 additions & 13 deletions app/components/elements/misc/ConditionalAd.ts

This file was deleted.

6 changes: 3 additions & 3 deletions app/components/screens/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ function Home() {
<View style={homeStyle.navigation}>
<Logo style={homeStyle.logo} fill={colors.gray} />
{developerMode && (
<TouchableOpacity style={homeStyle.appEnvironment} activeOpacity={0.8} onPress={handleAppEnvironment}>
<Text style={homeStyle.appEnvironmentText}>{codepushEnvironment}</Text>
</TouchableOpacity>
<TouchableOpacity style={homeStyle.appEnvironment} activeOpacity={0.8} onPress={handleAppEnvironment}>
<Text style={homeStyle.appEnvironmentText}>{codepushEnvironment}</Text>
</TouchableOpacity>
)}
<TouchableOpacity activeOpacity={0.8} onPress={handleOpenNav}>
<Menu style={homeStyle.menu} />
Expand Down
5 changes: 2 additions & 3 deletions app/components/screens/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import useSelectLists from '../../utils/lists';
import Select from '../elements/inputs/Select';
import TimeSignatureSelect from '../elements/inputs/TimeSignatureSelect';
import Alert from '../elements/misc/Alert';
import ConditionalAd from '../elements/misc/ConditionalAd';
import CountdownTimer from '../elements/misc/CountdownTimer';
import type { TimeSignaturePayload } from '../../store/globalStore';
import type { Sample } from '../../utils/lists';
Expand Down Expand Up @@ -192,7 +191,7 @@ function Settings() {
onRewardedClick={handleRewardedSamplesOpen}
compareSamples={global.unlockedSamples}
/>
<ConditionalAd>
{config.ads && (
<TouchableHighlight
onPress={handleRewardedSamplesOpen}
disabled={openTimeSigSelect || openSoundSelect}
Expand All @@ -203,7 +202,7 @@ function Settings() {
{t(hasAllRewards ? 'settings.keep_rewards' : 'settings.more_samples')}
</Text>
</TouchableHighlight>
</ConditionalAd>
)}
</View>
</View>
<View style={mainStyle.adSpace} />
Expand Down
2 changes: 1 addition & 1 deletion app/store/globalStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ const fetchPresetAndSamples = (state: State, payload: FetchResponse) => {
...state,
presets: payload.presets,
unlockedSamples: newUnlockedSamples,
unlockedPro: !isNil(payload.rewardedAt.pro),
unlockedPro: !config.ads || !isNil(payload.rewardedAt.pro),
rewardedAt: payload.rewardedAt,
ui: {
...state.ui,
Expand Down
4 changes: 2 additions & 2 deletions app/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { reducer as staticStoreReducer } from './staticStore';
import { t } from '../locales';
import Playback from '../sound';
import beats from '../sound/beats';
import { sliderStep } from '../tokens';
import { config, sliderStep } from '../tokens';
import { isPromise } from '../utils';
import { getSamples, getTimeSignatures, getUnlockedSamples } from '../utils/lists';
import type { Sample, TimeSig } from '../utils/lists';
Expand Down Expand Up @@ -45,7 +45,7 @@ const initialState = {
kick: 0,
},
ui: {
showAds: true,
showAds: config.ads,
isPlaying: false,
useBPM: 100,
useSample: sample,
Expand Down
3 changes: 2 additions & 1 deletion app/styles/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const settingsStyle = StyleSheet.create({
alignItems: 'flex-end',
display: 'flex',
flex: 1,
justifyContent: 'space-between',
gap: 100,
justifyContent: 'flex-start',
maxHeight: 750,
width: isTablet ? '80%' : '100%',
},
Expand Down
10 changes: 5 additions & 5 deletions app/utils/lists.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { includes, reduce } from 'lodash';
import { includes, map, reduce } from 'lodash';
import useLocale from '../locales';
import { config } from '../tokens';

export type Sample = {
label: string,
Expand Down Expand Up @@ -85,11 +86,10 @@ export const getSamples = (): Sample[] => ([
export const getUnlockedSamples = (): string[] => {
const samples = getSamples();

if (!config.ads) return map(samples, 'label');

return reduce(samples, (list: string[], sample: Sample) => {
if (includes([
'Acoustic',
'Hip-hop',
], sample.label)) {
if (includes(['Acoustic', 'Hip-hop'], sample.label)) {
return [...list, sample.label];
}

Expand Down

0 comments on commit c91f4c6

Please sign in to comment.