Skip to content
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
Expand Up @@ -52,15 +52,14 @@ class RNMBXAtmosphere(context: Context?) : AbstractSourceConsumer(context) {
}

fun addStyles() {
mAtmosphere?.also {
RNMBXStyleFactory.setAtmosphereLayerStyle(
it, RNMBXStyle(
context, mReactStyle!!,
mMap!!
)
)
} ?: run {
val atmosphere = mAtmosphere ?: run {
Logger.e("RNMBXAtmosphere", "mAtmosphere is null")
return
}
val reactStyle = mReactStyle ?: return
val map = mMap ?: return
RNMBXStyleFactory.setAtmosphereLayerStyle(
atmosphere, RNMBXStyle(context, reactStyle, map)
)
}
}
84 changes: 84 additions & 0 deletions example/src/examples/V10/AtmosphereRaceRepro.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { useMemo, useState } from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
import { Atmosphere, Camera, MapView } from '@rnmapbox/maps';

const STYLE_DARK = 'mapbox://styles/mapbox/dark-v11';
const STYLE_STANDARD = 'mapbox://styles/mapbox/standard';

const styles = StyleSheet.create({
map: {
flex: 1,
},
controls: {
position: 'absolute',
top: 50,
left: 16,
right: 16,
gap: 8,
backgroundColor: 'rgba(0,0,0,0.35)',
borderRadius: 10,
padding: 10,
},
text: {
color: 'white',
},
});

const AtmosphereRaceRepro = () => {
const [styleURL, setStyleURL] = useState(STYLE_DARK);
const [showAtmosphere, setShowAtmosphere] = useState(true);

const atmosphereStyle = useMemo(() => {
const isDark = styleURL === STYLE_DARK;
return {
color: isDark ? 'rgba(29,44,62,1)' : 'rgba(255,255,255,1)',
highColor: isDark ? 'rgba(11,11,25,1)' : 'rgba(255,255,255,1)',
spaceColor: isDark ? 'rgba(11,11,25,1)' : 'rgba(255,255,255,1)',
horizonBlend: 0.03,
starIntensity: isDark ? 0.6 : 0,
};
}, [styleURL]);

function flipStyle() {
setStyleURL((prev) => (prev === STYLE_DARK ? STYLE_STANDARD : STYLE_DARK));
}

function remountAtmosphere() {
setShowAtmosphere(false);
requestAnimationFrame(() => setShowAtmosphere(true));
}

return (
<View style={styles.map}>
<MapView style={styles.map} styleURL={styleURL} surfaceView={false}>
<Camera
centerCoordinate={[8.856142, 45.60942]}
zoomLevel={13}
pitch={45}
heading={0}
/>
{showAtmosphere ? <Atmosphere style={atmosphereStyle} /> : null}
</MapView>

<View style={styles.controls}>
<Text style={styles.text}>
Repro: tap quickly to trigger Atmosphere mount/style race
</Text>
<Button title="Toggle style (dark - standard)" onPress={flipStyle} />
<Button title="Remount Atmosphere" onPress={remountAtmosphere} />
</View>
</View>
);
};

export default AtmosphereRaceRepro;

/** @type ExampleWithMetadata['metadata'] */
const metadata = {
title: 'Atmosphere Race Repro',
tags: ['Atmosphere'],
docs: `
Minimal reproducer for Atmosphere style/remount race while changing map style.
`,
};
AtmosphereRaceRepro.metadata = metadata;
1 change: 1 addition & 0 deletions example/src/examples/V10/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as CameraAnimation } from './CameraAnimation';
export { default as AtmosphereRaceRepro } from './AtmosphereRaceRepro';
export { default as GlobeProjection } from './GlobeProjection';
export { default as MapHandlers } from './MapHandlers';
export { default as Markers } from './Markers';
Expand Down
Loading