Gradient slider in React Native? - react-native

Is it possible to implement slider with static gradient track in React Native using any 3rd party library or what-soever?
Illustrative image from Google:
Right now I'm using sldier from #react-native-community/slider, but it doesn't seem to support gradient slider track? I can customize minimumTrackTintColor and maximumTrackTintColor, but I would like to have static gradient track independent of the indicator position. I have looked into other 3rd party slider libraries as well, but encountered the same problem.
So, is there any way in any library to achieve this in React Native?

I dont think any package upfront gives this functionality, but you can always use linear-gradient. this library, make a view with. gradient like that, and on top of that, by using position:'relative' make a cursor and slide it by using rn-draggable . You will need to work out on that, but you can create a new functionality , and maybe publish it so that it can be used by others in future.
Hopeit helps.feel free for doubts

Inspired from what #Gaurav_Roy answered above, in the end, I achieved what I wanted with react-native-gesture-responder . I positioned my custom gradient slider track and slider dot as images and used createResponder from the library to capture user interactions with the slider dot. Then calculated the distance between dot position and track edges to get the value.

Related

Measure fields and area using google maps api in react native

I want to implement a feature in my react native application to let the user measure area or fields with two different methods the first is manual like manually drawing the fields area in the map and secondly automatically by using the gps and entering points while he walk around the field .
Could please anyone share some resosurces or any help material that may assist me in achieving this feature.
Thanks in advance
It is totally doable. Since you didn't mention any particular library, let me explain using react-native-maps (it is an awesome package :). Let's first discuss using the drawing (not sure if you literally mean drawing - at least I don't think you need to add complexity in this).
You can provide the <MapView> component provided by the package with a onTap method, when the user taps, you can add the coordinate a list of coordinates like this:
const [coordinates, setCoordinates] = useState([]);
then in the map, you can do
<MapView onPress={(coords) => setCoordinates([...coordinates, coords])} ...rest of the code
when the user is done, you can use a bit of mathematics (https://www.mathopenref.com/coordpolygonarea.html) or even a polygon package to calculate the area (https://www.npmjs.com/package/polygon).
Well, the second use case is easier I think as no extra interaction is needed since user can input the coordinates which you can again put in the coordinates array and use to calculate area.
I hope it helps :)

NativeScript-Vue button with linear gradient background and image

In NativeScript with vue.js, I'm trying to figure out if it is possible to have a button which has a linear gradient background and shows an image above the button text. When I set up the CSS to do that, it doesn't seem to work.
I set up a playground to demonstrate: https://play.nativescript.org/?template=play-vue&id=kICEBa&v=1.
Am I doing something wrong, or is this simply not supported by NativeScript-Vue?
If it's not supported by CSS, is there some other way to achieve this result?
I don't think having both on same element is yet supported. You may raise a feature request to support both.
Meanwhile wrap your button with a layout / content view and apply the gradient on it.

ReactJS - is there any recommended way to games (2D Tile Maps)

We are doing a small mobile game with react-native. But now we are not sure if react-native is a good choice for what we wanted to create.
Our game is simply just working with tiles in a not that small "map". Lets say its 1000 x 1000 Tiles so at the end 1.000.000 Tiles.
1) Our first try was to render 1 Mio. Components - which ended bad. Even 100 x 100 is like impossible to render with react-native.
2) We ended up to add some logic which renders just tiles inside the view. But when doing any action (and new tiles get rendered) the app is laggy as hell.
3) So we made sure no Tile get ever recreated and instead we just changed props so the tile change the position instead of being recreated. This ended up also in a laggy as hell experience (even when its like 20 Tiles just changing the prop).
After these we decided that React-Native has no nice performance for what we wanted to create: A big tile map with some interactions.
4) So we were thinking of using canvas for drawing the tiles in our react-native app, but it seems that this is also not the common way. We've found some canvas packages for react-native but these are just adding a few components which are useless for our project - with these components we would also end up by rendering components like . But the goal would be to have one ref where we can use the canvas benefits.
So - if react-native is too laggy for doing stuff like this in his own way and canvas is not useable as it is in web what would be the recommended way to solve a project like this ? Or is the answer maybe that react-native is the wrong system to solve a project like this ? Any suggestions ?
IMHO, I will never recommend react-native to make a game like you are describing (with tilemap), less-UI-focused games like poker, trading cards is totally fine though.
But you are likely rendering thousands of tiles without any clipping? How about try to enable View clipping? See removeClippedSubviews here: https://facebook.github.io/react-native/docs/view.html
If you still want to push with react-native, I suggest using plugins like this: https://github.com/ProjectSeptemberInc/gl-react-native
The purpose is to have an OpenGL ES canvas to accelerate your game rendering.
Otherwise, for 2D games, cocos2d-js seems fit to you (it seems your background is javascript), although it will requires some compiler knowledge to get the game actually running on mobile device. The other solution would be Unity 3D (2D is completely find with this engine). Each engine has their own pros/cons, so I would suggest you to try both at basic level to see which one is more suitable.

Improve perfomance of my threejs

I have some issues about my model. Is is an easy model buy I can not make It work well...
I upload my project here: http://webgl.drapps.info
I have a car model with some pieces that change material when mouse is over them. I use threex.domevent.js library with "on" function. My model is loaded by json files.
Issue 1
when mouse is out of canvas, threejs detects that mouse is over a piece of my model, but this is not true, and that piece change its material (triggering mouseOver event).
Furthermore, I tried to get better mouseover event because even when mouse is really over a piece, that event doesn't trigger.
Issue 2
This is about TrackballControls. Is there any way to control rotation of my world? I mean: rotation only in one axis, rotation only for 180 degrees, etc... Is there any tutorial or article to learn how to rotate and translate camera?
Thanks for everything, I will so please to anybody who wants answer this... because I am a little lost
Thanks
Sorry, but you are out of luck.
Question 1. Yikes! You are using threex.js which is a third-party app that hasn't been updated in almost a year, so I can't help you with that.
You are also using an older version of three.js. Please update to the current version.
If you still have problems, post a new question with a simple demo -- not your entire project. Better yet, Google your question first.
Question 2. TrackballControls is not part of the library -- it is part of the examples -- so it is not officially supported. If you are not happy with it, you will have to hack the code yourself.
This question has come up a lot. Google it. To the best of my knowledge, there is not a good solution.
Personally, I would use OrbitControls in your case -- it keeps the scene right-side-up, and you can constrain the maximum polar angle, keeping the camera "above ground".
The best examples/tutorials are the official three.js examples, which will work with the current version of the library.
I can't help with issue 1.
Issue2:
I am also working on a project to visualize vehicles and needed to be able to rotate. I also tried Trackballcontrolls but it did not suit my needs.
What I ended up doing was creating a a master Object3d and then instead of adding objects/models to the scene, I added them to the master Object3d. That way to rotate everything in the scene, I just had to rotate the master object.
To actually do the rotation I just used the code from one of the cube examples.

custom colors in bing maps?

I was looking at http://www.msnbc.msn.com/id/26295161/ns/weather/ and noticed that the flash map is provided by bing and have a custom color scheme. I have a similar need to show maps with a black & white colortheme, is it possible using their api or have they made custom tiles ? (doesnt seem feasible to provide tiles for alls maps on all levels :)
If you are not wedded to Bing maps, you could look into Mapbox, which provide maps based on OpenStreetMap in any style that you desire.
This question is still not answered and even if it's kind of old, I think it matters.
In fact, they're not using different tiles or a custom tile scheme. You can see those in the network inspection tool.
Since they're inside a Flash application, they can easily change the color of the image using filter on image (ColorMatrixFilter) and changing dynamically on the client side the rendered colors.
Well now some years later you can: https://msdn.microsoft.com/en-us/library/mt823636.aspx :-)
(I got here by looking for some sample styles and thought I add the link for anybody else finding this question)
Perhaps a custom tile skinner is that you need: http://rbrundritt.wordpress.com/2009/11/27/bing-maps-custom-tile-skinner/
In this example, the author changes the color of roads using ColorMatrix and ColorMap:
The two key methods used to transform the colors
consist of using ColorMatrix or a ColorMap. By
using a color matrix all the colors on the tile
can be changed within a couple lines of code. Using
a ColorMap allows you to change one color at a
time. This is useful if you only want to change a
few colors on the map.