Why do you use useLayoutEffect instead of useEffect to create a new history object in BrowserRouter? - react-router

I looked at some of the source code, but I had some problems in them. It should be here - BrowserRouter, Why do you use useLayoutEffect instead of useEffect to create a new history object in BrowserRouter? If you have free time, can you solve my puzzle?

I had a similar problem one time. I hope can help you. useLayoutEffect is synchronized with the screen. It prevent visual bug during refreshing.
https://reactjs.org/docs/hooks-reference.html

Related

How can i implement.GMSMapViewDelegate in another class instead of ViewController

I'm working on swiftui views instead of traditional viewController, i used UIViewRepresentable protocol to wrap the GMSMapView. Now i would set a GMSMapViewDelegate to the represented mapView. the traditional way is to implement the protocol on the ViewController that contains the mapView but here while i'm using Swiftui views i'm really got lost. i tried to implement the delegate on a separate class but it did't work for e and couldn't get the current camera target when i moved it.
Please can anyone guide me, this is my first steps in iOS development.
Thank you all.
Thanks all for giving intention to my question, finally i solved it.
Just created a class that inherit from GMSMapViewDelegate and made it as an environment object so all views can access it.
best wishes to all.

SparkAR How to change the lips size with code?

Im creating a new filter effect but i wanted to change the size of the lips. I thought that the faceDistortionPack will solve the problem but it only widens it. I need to expand the upper lip and the lower. So i think it's necessary to script the code but i don't know about that. I tried to create one based on the tutorial in the site but it doesn't work. Can you help me?
The easiest way is to use Sculptgl to make the face deformations.
Upload the "faceMesh.obj" (found in Face Reference Assets: Face-reference-assets-classic.zip)
Make the changes you want in the face and save the new .obj
Spark Ar: Add a new Face Mash in your faceTracker OR use an existent one.
Select the Face Mash, go to "Deformations" -> Import New 3D Object
Voi a l

React-Router - componentDidMount not called when navigating to URL

I'm a little stumped on this one. I defined a route called classes/:id. When navigating to that route in the app, the componentDidMount() is called. However, when reloading the page or copying and pasting the URL the page completely loads, but the componentDidMount() method is not called at all.
From what I have read, the reason is because the same component mounted even though the page is being reloaded which is why the lifecycle method does ever get fired off.
What are some ways to handle this? Your help is greatly appreciated. Thanks!
componentDidMount will not be called again if you are already at a classes/:id route. You'll probably want to do something along the lines of:
componentDidUpdate(prevProps) {
if (this.props.id !== prevProps.id) {
// fetch or other component tasks necessary for rendering
}
}
I try to avoid any mixins (see willTransitionTo), as they are considered harmful.
Although componentDidMount does not fire when changing routes for the same component, componentWillUpdate and componentWillReceiveProps do.
From there, you can detect parameter changes, and can fire your actions accordingly.
the componentWillReceiveProps,componentDidUpdate lifecycle will receive the new props and then setState to change state to trigger render method.
I just dealt with this exact issue, took me a while to figure out the problem. I'm sure everything previously suggested works great as a solution. How I solved the problem was a bit different though. My componentDidMount function was essentially just providing a state update, so I just moved the functionality directly into the state and bypassed componentDidMount.
Honestly, I'm not sure if this is best practice or not (very happy for feedback if it isn't), but it's running efficiently and works great so far.

Code for A Graphical User Interface window

How would someone go about coding a 'window'? I'm starting to make a GUI, and I want to learn how to code one. One that can be skinnable, and one that actually loops and creates itself at runtime. I understand that this might be a bit vague, so I'll add details.
One that actually 'creates' itself. Most GUI tutorials I've looked on depends on an 'image' that just gets added on the screen. I want to be able to use skins in my windows. One where my 'skin' is just a collection of 'borders'. Then when I insert window.create(50,50) where 50,50 is my height, width, It would just create that window, following the skin.
I understand that it probably follows just like when a language draws a rectangle, it just follows a different set of rules (maybe?). However, for all my Google-fu skills I cannot find a tutorial that teaches me this.
Please Help. I didn't include the language I used as you can see, because I believe I just need to know how to create one. Anyway though, I am using Actionscript 3. A tutorial would be just fine, or even A SINGLE CLASS THAT HAS THIS FUNCTIONALITY, I'll just study the code. Or if you know one, maybe a whole book about GUI and programming it :D
Pure As3.0 GUI coding is quite troublesome. I try to Googling, but not come out well. anyway for my case, i generate using a SWC, and Class Mapping and Customizing. but i'm not sure best way. in other way i use a bit101 library. this is gives me want Window, Charts, Componets easily of high abstraction. see the below image.
It can be pretty hard and complicated to do, or very easy, it just depends on how flexible your solution should be. You need firstly to design a structure of your program and approach to the problem.
I like to go from the image of how it should look like from API point of view. I think I would create a GUI element like this:
var wholeGui:MyGUI = new MyGUI();
var window:IGuiElement = new GuiWindow(dataObject, skinObject);
wholeGui.addElement(window);
So what would you need?
1) Object that would manage all GUI elements. Why? Simply because your GUI elements shouldn't be destroyed by themselves if user will click "X" on your little window. The wholeGui object would manage them and listen for any events including those that would destroy them. You may consider creating custom events for interaction between the wholeGui object and your window object if this interaction is going to be complicated.
2) Interface for your GUI objects. Some problem here is that AS3 actually doesn't have interface for Sprite, and you would like to interact with it like with extended Sprite. The workaround here is to have in this interface a declaration like this:
function asSprite():Sprite;
And your implementation in GuiWindow would look like this:
public function asSprite():Sprite {
return this;
}
And your GuiWindow class should extend Sprite of course. Then you would have access to it's Sprite properties and methods by writing for example: window.asSprite.startDrag();
This interface should give you abilities that you need to operate on your GUI element.
3) Class for your GUI element, in this example GuiWindow.
4) Class for your data that would be injected into your element. If you would load data dynamically, and from some location, you would need to deal with the situation when no data can be provided - but that logic would be inside your window.
5) Class for your skin - so you would be able to dynamically create a skin object and use it to create your window in a way you want.
That's just few thoughts to consider.
PS. It may be good idea to fill GuiWindow object with data AFTER creating it, and not in constructor, as you would be able to visualize loading process then.

AS3: How to use GTween?

I'm working with the latest version of the SDKs and FlashDevelop. So far, everything about my setup works fine, including external libraries. But when I use GTween, nothing happens. At all. I've tried several of the included samples and some of my own code, and all I get is a blank window or nothing moves, respectively. No errors, but also no action.
Could someone paste in some minimal code that just loads GTween and has it move a sprite? I'd like to have a known good for comparison so I can see if I'm missing something obvious or if there's something weird going on.
Thanks! :)
i just downloaded GTween and copied the com folder to my source...
... this worked fine:
package{
import com.gskinner.motion.GTween;
import flash.display.Sprite;
public class GtTest extends Sprite{
public function GtTest(){
var ball:Sprite = new Sprite();
ball.graphics.beginFill(0xFF0000);
ball.graphics.drawCircle(300,300,10);
addChild(ball);
var myTween:GTween = new GTween(ball, 2, {x:100, y:100}, {swapValues:true});
}
}
}
hope that helps ;)
Are you sure you're compiling to the version of flashplayer you have? It's possible that your player needs to be updated. Hard to tell from this info what could be the problem.
Also GTween is ok, and I have it in one project and used it fairly recently, but there are better alternatives. (gtween was last updated in 2009)
I've been using eaze a lot, but I know most as3-ers flock to TweenLite (for a good reason).