Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: implement MovePointShapeAnimator and ChangeLineOffsetsShapeAnimator #3281

Merged
merged 122 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
95c21c9
Fix invalid return and property errors
naftalibeder Dec 13, 2023
fd04c09
Re-add layout metric prop
naftalibeder Dec 14, 2023
03c4205
Fix invalid return and property errors
naftalibeder Dec 13, 2023
58eddeb
Re-add layout metric prop
naftalibeder Dec 14, 2023
63766d8
Fix invalid return and property errors
naftalibeder Dec 13, 2023
e63b1d8
Finish move-point implementation and refactor common animator
naftalibeder Dec 19, 2023
3b6af35
Add animator type
naftalibeder Dec 19, 2023
7b811e4
Fix duration unit and rename variables for clarity
naftalibeder Dec 19, 2023
5aae28a
Add new animated point with animator example
naftalibeder Dec 19, 2023
d15d8a4
Remove log
naftalibeder Dec 19, 2023
0fbe9b2
Always start new animation from current position
naftalibeder Dec 19, 2023
033c3d4
Fix accidental rename
naftalibeder Dec 19, 2023
0540c62
Re-add getShape and override it
naftalibeder Dec 20, 2023
06e492d
Rename arg
naftalibeder Dec 20, 2023
ac4ed43
Update lockfiles
naftalibeder Dec 20, 2023
995334b
Fix prop
naftalibeder Dec 20, 2023
0ca879f
Move interface to module index file
naftalibeder Dec 20, 2023
8c8e403
Provide timestamp instead of delta for comparisons
naftalibeder Dec 20, 2023
c141ca2
Fix import
naftalibeder Dec 20, 2023
a227916
Implement line-offset animator
naftalibeder Dec 22, 2023
992a776
Implement end offset animation
naftalibeder Dec 22, 2023
cd15995
Choose random offsets based on line length
naftalibeder Dec 22, 2023
1d5fbad
Add reset button and improve copy
naftalibeder Dec 22, 2023
0144490
Move global duration into function arg
naftalibeder Jan 4, 2024
6b13b43
Rename coordinate arg for consistency
naftalibeder Jan 4, 2024
9f753b8
Undo delete
naftalibeder Jan 4, 2024
e58822a
Expose method for updating entire line
naftalibeder Jan 5, 2024
2c84be0
Revert instant shape update
naftalibeder Jan 5, 2024
c388701
Add and update reject calls on error
naftalibeder Jan 5, 2024
e505808
Clean up
naftalibeder Jan 5, 2024
d59fcfe
Avoid syntax warnings
naftalibeder Jan 5, 2024
0d6fa5d
Implement move-point animator
naftalibeder Jan 5, 2024
58dc91d
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Jan 9, 2024
8198f2b
Implement line-offsets animator on Android
naftalibeder Jan 9, 2024
05adac9
Add checks to avoid illegal turf measurements
naftalibeder Jan 10, 2024
799dee1
Restart animator if stopped when setting new target values
naftalibeder Jan 10, 2024
bf96d8a
Fix whitespace
naftalibeder Jan 10, 2024
ae064dc
Provide default return value for getShape() like on Android
naftalibeder Jan 10, 2024
7374638
Clean up passthrough function
naftalibeder Jan 10, 2024
6db2f2e
Return empty feature collection to avoid crash-on-render 0-length line
naftalibeder Jan 10, 2024
8d029d9
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Jan 16, 2024
d15cc79
Switch to sliders and allow offsets to sum greater than line length
naftalibeder Jan 16, 2024
2087832
Refactor offset overflow handling
naftalibeder Jan 16, 2024
367ed69
Update generated files
naftalibeder Jan 16, 2024
8e47b2a
Increase padding
naftalibeder Jan 16, 2024
0b81e38
Fix divide-by-zero and refactor
naftalibeder Jan 16, 2024
23df984
Clean up imports
naftalibeder Jan 16, 2024
1153517
Remove second element from getAnimatedShape return value
naftalibeder Jan 16, 2024
783d72c
Fix name
naftalibeder Jan 16, 2024
7fe92eb
Unsubscribe consumer on removal from map
naftalibeder Jan 16, 2024
c03f042
Conditionally start and stop timer based on animation progress
naftalibeder Jan 17, 2024
ba11b88
Remove unneeded null check
naftalibeder Jan 17, 2024
c71198d
Port timer start/stop logic to point animator
naftalibeder Jan 17, 2024
0d704ba
Abstract out animatable value helper class
naftalibeder Jan 17, 2024
c585a68
Rename directory
naftalibeder Jan 17, 2024
ec95c05
Fix timestamp arg
naftalibeder Jan 17, 2024
333c125
Remove unneeded start method from JS interface
naftalibeder Jan 17, 2024
999682e
Add padding
naftalibeder Jan 17, 2024
af5e2ad
Clean up imports
naftalibeder Jan 17, 2024
55e3028
Port new logic to iOS implementation
naftalibeder Jan 18, 2024
ee02b0e
Enable randomizing line
naftalibeder Jan 18, 2024
279f673
Abstract out single-refresh logic and make public
naftalibeder Jan 18, 2024
2dcbe54
Add refresh to protocol
naftalibeder Jan 18, 2024
ddc4e9c
Implement single-refresh functionality
naftalibeder Jan 18, 2024
c59eaa7
Fix timer lifespan calculation
naftalibeder Jan 18, 2024
6a228bc
Keep randomized line centered
naftalibeder Jan 19, 2024
af8bb1e
Switch from Timer to CADisplayLink
naftalibeder Jan 19, 2024
7b89c56
Switch unit entirely to seconds on native side
naftalibeder Jan 19, 2024
a9da689
Set completion ratio to 1 if duration is 0
naftalibeder Jan 19, 2024
8e5bba4
Accept optional offsets when setting new line
naftalibeder Jan 19, 2024
e062db5
Port optional offsets when updating line to Android
naftalibeder Jan 19, 2024
f99a81d
Rename timestamp for clarity
naftalibeder Jan 19, 2024
fac01cf
Fix syntax bug
naftalibeder Jan 19, 2024
ed6073d
Simplify literal declarations
naftalibeder Jan 22, 2024
59de35a
Correctly handle zero duration for moving point
naftalibeder Jan 22, 2024
b14ebe4
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Jan 22, 2024
1b333fb
Prevent asymmetrical animator consumer removal
naftalibeder Jan 24, 2024
98c14e9
Augment log
naftalibeder Jan 24, 2024
0b39f22
Port animator subscriber removal bug to iOS
naftalibeder Jan 24, 2024
405fc13
Refactor
naftalibeder Jan 24, 2024
3018227
Refactor and allow setting duration
naftalibeder Jan 24, 2024
2ef49b8
Test don't unsubscribe for any remove reason
naftalibeder Jan 24, 2024
b06c86d
Re-enable unsubscribe on style change
naftalibeder Jan 25, 2024
1584d17
Add alert log for source remove reason
naftalibeder Jan 25, 2024
2c6916b
Unsubscribe only on view removal
naftalibeder Jan 25, 2024
51d9542
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Jan 30, 2024
d913228
Upgrade package to avoid new-arch error
naftalibeder Jan 30, 2024
53dadfb
Ignore .cxx (generated during new-arch build)
naftalibeder Jan 30, 2024
47bef57
Remove unused start method
naftalibeder Jan 30, 2024
6fbb959
Update lockfile
naftalibeder Jan 30, 2024
5a2c826
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Jan 30, 2024
2161ee7
Refactor logger to enable tag and deprecate quasi-duplicate functions
naftalibeder Feb 2, 2024
fa96cea
Remove log
naftalibeder Feb 2, 2024
1358b47
Remove Page component
naftalibeder Feb 2, 2024
3801be2
Remove Page component
naftalibeder Feb 2, 2024
5381b6a
Remove log
naftalibeder Feb 2, 2024
3ee12b6
Fix component removal
naftalibeder Feb 2, 2024
378039b
Unusbscribe on new shape input in case of changed animator
naftalibeder Feb 2, 2024
08963e5
Remove logs
naftalibeder Feb 2, 2024
6a5eb70
Re-add v11 compat import and clean up imports
naftalibeder Feb 2, 2024
f9137c2
Allow setting line offsets with zero duration
naftalibeder Feb 2, 2024
a7d3de7
Re-add example and fix references
naftalibeder Feb 2, 2024
947cb2b
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Feb 5, 2024
ca07da1
Remove ruby version lock
naftalibeder Feb 5, 2024
66c0e27
Update lockfile
naftalibeder Feb 5, 2024
70b424a
Make error enum public
naftalibeder Feb 5, 2024
65c1702
Add animator stub
naftalibeder Feb 5, 2024
142877a
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Feb 5, 2024
75cfdcc
Specify Swift version in action
naftalibeder Feb 6, 2024
939f0ef
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Feb 7, 2024
153d3e4
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Feb 8, 2024
8ef5e86
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Feb 9, 2024
9597cd9
Make Swift version unspecified
naftalibeder Feb 12, 2024
0376c17
Revert CI action to use Swift 5.1
naftalibeder Feb 12, 2024
7dae0aa
Add explicit returns
naftalibeder Feb 12, 2024
590a353
Remove empty swift version lock
naftalibeder Feb 12, 2024
1e9b410
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Feb 13, 2024
854e898
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Feb 16, 2024
126b305
Merge branch 'main' of github.com:rnmapbox/maps into truckmap/prod
naftalibeder Feb 21, 2024
09582a1
Remove swift version
naftalibeder Feb 22, 2024
5aef988
Switch to rnmbx logger
naftalibeder Feb 22, 2024
9bd4376
Re-add Swift version specifier
naftalibeder Feb 22, 2024
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
15 changes: 13 additions & 2 deletions android/src/main/java/com/rnmapbox/rnmbx/RNMBXPackage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ import com.rnmapbox.rnmbx.modules.RNMBXOfflineModule
import com.rnmapbox.rnmbx.modules.RNMBXOfflineModuleLegacy
import com.rnmapbox.rnmbx.modules.RNMBXSnapshotModule
import com.rnmapbox.rnmbx.modules.RNMBXTileStoreModule
import com.rnmapbox.rnmbx.shape_animators.RNMBXMovePointShapeAnimatorModule
import com.rnmapbox.rnmbx.shape_animators.ShapeAnimatorManager
import com.rnmapbox.rnmbx.shapeAnimators.RNMBXChangeLineOffsetsShapeAnimatorModule
import com.rnmapbox.rnmbx.shapeAnimators.RNMBXMovePointShapeAnimatorModule
import com.rnmapbox.rnmbx.shapeAnimators.ShapeAnimatorManager
import com.rnmapbox.rnmbx.utils.ViewTagResolver

class RNMBXPackage : TurboReactPackage() {
Expand Down Expand Up @@ -103,6 +104,7 @@ class RNMBXPackage : TurboReactPackage() {
RNMBXImageModule.NAME -> return RNMBXImageModule(reactApplicationContext, getViewTagResolver(reactApplicationContext, s))
RNMBXPointAnnotationModule.NAME -> return RNMBXPointAnnotationModule(reactApplicationContext, getViewTagResolver(reactApplicationContext, s))
RNMBXMovePointShapeAnimatorModule.NAME -> return RNMBXMovePointShapeAnimatorModule(reactApplicationContext, getShapeAnimators(s))
RNMBXChangeLineOffsetsShapeAnimatorModule.NAME -> return RNMBXChangeLineOffsetsShapeAnimatorModule(reactApplicationContext, getShapeAnimators(s))
}
return null
}
Expand Down Expand Up @@ -292,6 +294,15 @@ class RNMBXPackage : TurboReactPackage() {
false,
isTurboModule
)
moduleInfos[RNMBXChangeLineOffsetsShapeAnimatorModule.NAME] = ReactModuleInfo(
RNMBXChangeLineOffsetsShapeAnimatorModule.NAME,
RNMBXChangeLineOffsetsShapeAnimatorModule.NAME,
false,
false,
false,
false,
isTurboModule
)
moduleInfos
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.events.Event
import com.facebook.react.uimanager.events.EventDispatcher
import com.rnmapbox.rnmbx.events.IEvent
import com.rnmapbox.rnmbx.utils.Logger

/**
* Created by nickitaliano on 8/23/17.
Expand Down Expand Up @@ -40,14 +41,19 @@ abstract class AbstractEventEmitter<T : ViewGroup?>(reactApplicationContext: Rea
return
}
mRateLimitedEvents[eventCacheKey] = System.currentTimeMillis()
mEventDispatcher!!.dispatchEvent(
AbstractEvent(
event.iD,
event.key,
event.canCoalesce(),
event.toJSON()

try {
mEventDispatcher!!.dispatchEvent(
AbstractEvent(
event.iD,
event.key,
event.canCoalesce(),
event.toJSON()
)
)
)
} catch (e: Exception) {
Logger.e("Error dispatching event:", e.toString())
}
}

override fun addEventEmitters(context: ThemedReactContext, view: T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
package com.rnmapbox.rnmbx.components.styles.sources

import android.content.Context
import com.mapbox.maps.extension.style.sources.generated.GeoJsonSource
import com.rnmapbox.rnmbx.utils.ImageEntry
import android.graphics.drawable.BitmapDrawable
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReadableMap
import com.rnmapbox.rnmbx.components.mapview.RNMBXMapView
import com.rnmapbox.rnmbx.events.FeatureClickEvent
import com.facebook.react.bridge.WritableMap
import com.facebook.react.bridge.WritableNativeMap
import com.mapbox.bindgen.Value
import com.mapbox.geojson.Feature
import com.rnmapbox.rnmbx.events.AndroidCallbackEvent
import com.mapbox.geojson.FeatureCollection
import com.mapbox.geojson.GeoJson
import com.mapbox.geojson.Geometry
import com.mapbox.maps.*
import com.mapbox.maps.extension.style.expressions.generated.Expression
import com.rnmapbox.rnmbx.shape_animators.ShapeAnimationConsumer
import com.rnmapbox.rnmbx.shape_animators.ShapeAnimator
import com.rnmapbox.rnmbx.shape_animators.ShapeAnimatorManager
import com.mapbox.maps.extension.style.sources.generated.GeoJsonSource
import com.rnmapbox.rnmbx.components.RemovalReason
import com.rnmapbox.rnmbx.components.mapview.RNMBXMapView
import com.rnmapbox.rnmbx.events.AndroidCallbackEvent
import com.rnmapbox.rnmbx.events.FeatureClickEvent
import com.rnmapbox.rnmbx.shapeAnimators.ShapeAnimationConsumer
import com.rnmapbox.rnmbx.shapeAnimators.ShapeAnimator
import com.rnmapbox.rnmbx.utils.Logger
import com.rnmapbox.rnmbx.v11compat.feature.*
import java.net.URL
import java.util.ArrayList
import java.util.HashMap

import com.rnmapbox.rnmbx.v11compat.feature.*
private const val LOG_TAG = "RNMBXShapeSource"

class RNMBXShapeSource(context: Context, private val mManager: RNMBXShapeSourceManager) :
RNMBXSource<GeoJsonSource>(context), ShapeAnimationConsumer {
Expand All @@ -47,13 +43,22 @@ class RNMBXShapeSource(context: Context, private val mManager: RNMBXShapeSourceM
}

override fun addToMap(mapView: RNMBXMapView) {

// Wait for style before adding the source to the map
mapView.getMapboxMap().getStyle {
val map = mapView.getMapboxMap()
super@RNMBXShapeSource.addToMap(mapView)
}
}

override fun removeFromMap(mapView: RNMBXMapView, reason: RemovalReason): Boolean {

if (reason == RemovalReason.VIEW_REMOVAL) {
mShapeAnimator?.unsubscribe(this)
}
return super.removeFromMap(mapView, reason)
}

override fun setId(id: Int) {
super.setId(id)
mManager.tagAssigned(id)
Expand Down Expand Up @@ -85,7 +90,8 @@ class RNMBXShapeSource(context: Context, private val mManager: RNMBXShapeSourceM
mShapeAnimator = shapeAnimator
shapeAnimator.subscribe(this)

shapeUpdated(shapeAnimator.getShape())
val shape = shapeAnimator.getShape()
shapeUpdated(shape)
}
} else {
mShape = geoJSONStr
Expand All @@ -108,8 +114,8 @@ class RNMBXShapeSource(context: Context, private val mManager: RNMBXShapeSourceM
else -> {
Logger.e(
LOG_TAG,
"Cannot convert shape to GeoJSONSourceData, neitthe Geometry, nor Feature or FeatureCollection: $geoJson"
);
"Cannot convert shape to Geometry, Feature, or FeatureCollection: $geoJson"
)
return null
}
}
Expand Down Expand Up @@ -214,7 +220,7 @@ class RNMBXShapeSource(context: Context, private val mManager: RNMBXShapeSourceM
)
) { features ->
if (features.isError) {
Logger.e("RNMBXShapeSource", String.format("Error: %s", features.error))
Logger.e(LOG_TAG, String.format("Error: %s", features.error))
} else {
val payload: WritableMap = WritableNativeMap()
val result: MutableList<Feature> = ArrayList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import com.rnmapbox.rnmbx.components.AbstractEventEmitter
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.bridge.ReadableType
import com.facebook.react.common.MapBuilder
import com.facebook.react.viewmanagers.RNMBXShapeSourceManagerInterface
import com.mapbox.bindgen.Value
import com.mapbox.maps.extension.style.expressions.generated.Expression
import com.rnmapbox.rnmbx.events.constants.EventKeys
import com.rnmapbox.rnmbx.events.constants.eventMapOf
import com.rnmapbox.rnmbx.shape_animators.ShapeAnimatorManager
import com.rnmapbox.rnmbx.shapeAnimators.ShapeAnimatorManager
import com.rnmapbox.rnmbx.utils.ExpressionParser
import com.rnmapbox.rnmbx.utils.Logger
import com.rnmapbox.rnmbx.utils.ViewTagResolver
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.rnmapbox.rnmbx.shapeAnimators

internal class AnimatableElement<T>(
var source: T,
var progress: T,
var target: T,
var startedAtSec: Double,
var progressDurationSec: Double,
var totalDurationSec: Double,
/** A function returning the difference in meters between the two values. */
var getDistanceRemaining: (a: T, b: T) -> Double
) {
fun distanceRemaining(): Double {
return getDistanceRemaining(source, target)
}

fun durationRatio(): Double {
return if (totalDurationSec > 0.0) {
progressDurationSec / totalDurationSec
} else {
1.0
}
}

fun setProgress(value: T, animatorAgeSec: Double) {
progress = value
progressDurationSec = (animatorAgeSec - startedAtSec)
}

fun reset(_source: T, _progress: T, _target: T, durationSec: Double, animatorAgeSec: Double) {
this.source = _source
this.progress = _progress
this.target = _target
this.startedAtSec = animatorAgeSec
this.progressDurationSec = 0.0
this.totalDurationSec = durationSec
}
}
Loading
Loading