4.8 C
New York
Friday, March 21, 2025
Home Blog Page 3802

Transitions in SwiftUI · objc.io


Throughout our SwiftUI Workshop we regularly discover that only a few folks appear to learn about transitions, though they are not very sophisticated and extremely helpful.

Transitions occur when a view is faraway from the view tree, or added to the view tree. Nevertheless, in case you’ve executed some SwiftUI, you should have observed that there is no such thing as a precise means so as to add views to the view tree — there is no such thing as a addSubview(_:). As a substitute, you’ll be able to solely add and take away views via the mixture of a state change and utilizing an if assertion (or swap or ForEach). In different phrases, views are by some means added and eliminated for us robotically, but transitions fireplace solely as soon as. Earlier than we dive into the main points of this, let’s contemplate a quite simple transition:

								struct ContentView: View {
    @State var seen = false
    var physique: some View {
        VStack {
            Toggle("Seen", isOn: $seen)
            if seen {
                Textual content("Hi there, world!")
            }
        }
        .animation(.default, worth: seen)
    }
}

							

Once we run the above code we will see the textual content fade out and in. That is the default transition (.opacity). When the view will get inserted into the view tree, it fades in, and as soon as it will get eliminated it fades out. Word that if the physique executes once more, the view does not fade in once more except the situation within the if assertion adjustments.

To construct up a psychological mannequin of what is taking place, we will contemplate the SwiftUI view tree for the above view:

SwiftUI views are ephemeral: the physique of ContentView will get executed and from it a render tree is created. This render tree is persistent throughout view updates, and it represents the precise views on display screen. As soon as the render tree is up to date, the worth for physique then goes away. Here is the render tree after the preliminary rendering:

As soon as we faucet the swap, a state change occurs and the physique of ContentView executes once more. The prevailing render tree is then up to date. On this case, SwiftUI observed that the if situation modified from false to true, and it’ll insert our Textual content view into the render tree:

The change within the render tree is what triggers the transition. Transitions solely animate when the present transaction accommodates an animation. Within the instance above, the .animation name causes the transition to animate.

The render tree doesn’t really exist with that identify or type, however is just a mannequin for understanding how SwiftUI works. We’re not utterly positive how this stuff are represented beneath the hood.

Once we change our view to have an if/else situation, issues get a bit extra fascinating. Here is the code:

								struct ContentView: View {
    @State var seen = false
    var physique: some View {
        VStack {
            Toggle("Seen", isOn: $seen)
            if seen {
                Textual content("Hi there, world!")
            } else {
                Picture(systemName: "hand.wave")
            }
        }
        .animation(.default, worth: seen)
    }
}

							

Once we render the preliminary view tree, it would include a VStack with a Toggle and a Textual content. As soon as the state adjustments from false to true, the textual content is changed by a picture. Within the ephemeral view tree there’s all the time both the Textual content or the Picture, by no means each. Within the render tree nonetheless, throughout the animation the tree will include each views:

As a result of we use the default transition, it seems to be just like the textual content fades into the picture and again. Nevertheless, you’ll be able to consider them as separate transitions: the textual content has a elimination transition (fade out) and the picture has an insertion transition (fade in).


We aren’t restricted to the default fade transition. For instance, here’s a transition that slides in from the vanguard when a view is inserted, and removes the view by scaling it down:

								let transition = AnyTransition.uneven(insertion: .slide, elimination: .scale)

							

We will then mix it with an .opacity (fade) transition. The .mixed operator combines each transitions in parallel to get the next impact:

								let transition = AnyTransition.uneven(insertion: .slide, elimination: .scale).mixed(with: .opacity)
VStack {
    Toggle("Seen", isOn: $seen)
    if seen {
        Textual content("Hi there, world!")
            .transition(transition)
    } else {
        Textual content("Hi there world!")
            .transition(transition)
    }
}
.animation(.default.velocity(0.5), worth: seen)

							

Word that within the pattern above, we used a seen worth to modify between the 2 Textual contents, though they’re the identical. We will simplify the code a bit by utilizing id(_:). At any time when the worth we go to id adjustments, SwiftUI considers this to be a brand new view within the render tree. Once we mix this with our data of transitions, we will set off a transition simply by altering the id of a view. For instance, we will rewrite the pattern above:

								let transition = AnyTransition.uneven(insertion: .slide, elimination: .scale).mixed(with: .opacity)
VStack {
    Toggle("Seen", isOn: $seen)
    Textual content("Hi there, world!")
        .id(seen)
        .transition(transition)
}
.animation(.default.velocity(0.5), worth: seen)

							

Earlier than the animation, the textual content is current, and throughout the animation the newly inserted view (with id(false)) is transitioned in, and the previous view (with id(true)) is transitioned out. In different phrases: each views are current throughout the animation:


When the builtin transitions do not cowl your wants, it’s also possible to create customized transitions. There may be the .modifier(lively:id) transition. When a view is not transitioning, the id modifier is utilized. When a view is eliminated, the animation interpolates in between the id modifier and the lively modifier earlier than eradicating the view utterly. Likewise, when a view is inserted it begins out with the lively modifier firstly of the animation, and ends with the id modifier on the finish of the animation.

Here is an instance of a favourite button with a customized transition. This is not an ideal implementation (we might not hardcode the offsets and width of the button) but it surely does present what’s attainable:

The complete code is out there as a gist.


Typically when performing a transition you may see sudden side-effects. In our case we had been virtually all the time in a position to resolve these by wrapping the view we’re transitioning inside a container (for instance, a VStack or ZStack). This provides some “stability” to the view tree that may assist stop glitches.

In essence, transitions aren’t very sophisticated. Nevertheless, reaching the end result you need is usually a bit tough generally. As a way to successfully work with transitions it’s important to perceive the distinction between the view tree and the render tree. And whenever you wish to have customized transitions, you additionally want to grasp how animations work. We cowl this in each our workshops and our e-book Pondering in SwiftUI.

If your organization is serious about a workshop on SwiftUI, do get in contact.

VulnNodeApp – A Susceptible Node.Js Utility

0




VulnNodeApp – A Susceptible Node.Js Utility

A susceptible software made utilizing node.js, specific server and ejs template engine. This software is supposed for instructional functions solely.

Clone this repository

git clone https://github.com/4auvar/VulnNodeApp.git

Utility setup:

  • Set up the newest node.js model with npm.
  • Open terminal/command immediate and navigate to the placement of downloaded/cloned repository.
  • Run command: npm set up

DB setup

  • Set up and configure newest mysql model and begin the mysql service/deamon
  • Login with root person in mysql and run beneath sql script:
CREATE USER 'vulnnodeapp'@'localhost' IDENTIFIED BY 'password';
create database vuln_node_app_db;
GRANT ALL PRIVILEGES ON vuln_node_app_db.* TO 'vulnnodeapp'@'localhost';
USE vuln_node_app_db;
create desk customers (id int AUTO_INCREMENT PRIMARY KEY, fullname varchar(255), username varchar(255),password varchar(255), e mail varchar(255), telephone varchar(255), profilepic varchar(255));
insert into customers(fullname,username,password,e mail,telephone) values("test1","test1","test1","[email protected]","976543210");
insert into customers(fullname,username,password,e mail,telephone) values("test2","test2","test2","[email protected]","9887987541");
insert into customers(fullname,username,password,e mail,telephone) values("test3","test3","test3","[email protected]","9876987611");
insert into customers(fullname,username,password,e mail,telephone) values("test4","test4","test4","[email protected]","9123459876");
insert into customers(fullname,username,password,e mail,telephone) values("test5","test5","take a look at 5","[email protected]","7893451230");

Set primary setting variable

  • Person must set the beneath setting variable.
    • DATABASE_HOST (E.g: localhost, 127.0.0.1, and so on…)
    • DATABASE_NAME (E.g: vuln_node_app_db or DB title you alter in above DB script)
    • DATABASE_USER (E.g: vulnnodeapp or person title you alter in above DB script)
    • DATABASE_PASS (E.g: password or password you alter in above DB script)
  • Open the command immediate/terminal and navigate to the placement of your repository
  • Run command: npm begin
  • Entry the applying at http://localhost:3000
  • SQL Injection
  • Cross Web site Scripting (XSS)
  • Insecure Direct Object Reference (IDOR)
  • Command Injection
  • Arbitrary File Retrieval
  • Common Expression Injection
  • Exterior XML Entity Injection (XXE)
  • Node js Deserialization
  • Safety Misconfiguration
  • Insecure Session Administration
  • Will add new vulnerabilities akin to CORS, Template Injection, and so on…
  • Enhance software documentation
  • In case of bugs within the software, be happy to create an points on github.
  • Be happy to create a pull request for any contribution.

You may attain me out at @4auvar

School college students head to campus with Mac and iPad

0



Microsoft Patches Zero-Day Flaw Exploited by North Korea’s Lazarus Group


Aug 19, 2024Ravie LakshmananVulnerability / Zero-Day

Microsoft Patches Zero-Day Flaw Exploited by North Korea’s Lazarus Group

A newly patched safety flaw in Microsoft Home windows was exploited as a zero-day by Lazarus Group, a prolific state-sponsored actor affiliated with North Korea.

The safety vulnerability, tracked as CVE-2024-38193 (CVSS rating: 7.8), has been described as a privilege escalation bug within the Home windows Ancillary Operate Driver (AFD.sys) for WinSock.

“An attacker who efficiently exploited this vulnerability might achieve SYSTEM privileges,” Microsoft stated in an advisory for the flaw final week. It was addressed by the tech large as a part of its month-to-month Patch Tuesday replace.

Cybersecurity

Credited with discovering and reporting the flaw are Gen Digital researchers Luigino Camastra and Milánek. Gen Digital owns plenty of safety and utility software program manufacturers like Norton, Avast, Avira, AVG, ReputationDefender, and CCleaner.

“This flaw allowed them to achieve unauthorized entry to delicate system areas,” the corporate disclosed final week, including it found the exploitation in early June 2024. “The vulnerability allowed attackers to bypass regular safety restrictions and entry delicate system areas that the majority customers and directors cannot attain.”

The cybersecurity vendor additional famous that the assaults had been characterised by means of a rootkit referred to as FudModule in an try and evade detection.

Whereas the precise technical particulars related to the intrusions are presently unknown, the vulnerability is harking back to one other privilege escalation flaw that Microsoft mounted in February 2024 and was additionally weaponized by the Lazarus Group to drop FudModule.

Particularly, it entailed the exploitation of CVE-2024-21338 (CVSS rating: 7.8), a Home windows kernel privilege escalation flaw rooted within the AppLocker driver (appid.sys) that makes it potential to execute arbitrary code such that it sidesteps all safety checks and runs the FudModule rootkit.

Cybersecurity

Each these assaults are notable as a result of they transcend a conventional Carry Your Personal Weak Driver (BYOVD) assault by making the most of a safety flaw in a driver that is already put in on a Home windows host versus “bringing” a vulnerable driver and utilizing it to bypass safety measures.

Earlier assaults detailed by cybersecurity agency Avast revealed that the rootkit is delivered by way of a distant entry trojan referred to as Kaolin RAT.

“FudModule is simply loosely built-in into the remainder of Lazarus’ malware ecosystem,” the Czech firm stated on the time, stating “Lazarus could be very cautious about utilizing the rootkit, solely deploying it on demand underneath the precise circumstances.”

Discovered this text fascinating? Comply with us on Twitter and LinkedIn to learn extra unique content material we put up.



The Anker 713 Charger is tiny, tremendous quick, and 51% off!

0


Anker 713 Charger

Most smartphones now not include chargers, leaving us all with the burden of getting to discover a charger to make use of with our new electronics. Not solely that, however it’s important to fear about choosing the right charger, and discovering one that may attain the speeds we have to fast-charge our smartphones. The Anker 713 Charger is a charger we normally advocate, and it’s out there at a 51% low cost proper now. This brings the entire value to a mere $19.59.

Get the Anker 713 Charger for simply $19.59

This provide is on the market immediately from Amazon. It’s labeled as a “restricted time deal,” which tells us the sale ought to finish comparatively quickly.

Anker Nano II 45W (Anker 713)

Anker Nano II 45W (Anker 713)

Anker Nano II 45W (Anker 713)

A compact, 45W USB energy brick

The Anker 713 is a single-port USB Sort-C charger. The GaN II tech outputs as much as 45W of energy.

A number of issues make the Anker 713 Nano II 45W an incredible charger for most individuals. For starters, it’s tremendous small. Because of GaN know-how, Anker could make this charger simply 1.49 x 1.38 x 1.62in and weighs simply 2.44oz. Regardless of its tiny dimension, it’s a mighty highly effective charger.

Whereas we’re specializing in smartphones right here, this charger can do greater than juice up handsets. It will probably additionally energy tablets and even many laptops, even when not all the time at full speeds.

At just below $20, this could possibly be the most effective charger you’ll find. It is best to in all probability join one quickly, as we’re undecided how lengthy the provide will final. If you wish to think about some options, although, you too can check out our listing of the greatest wall chargers.

Additional charger offers from UGREEN and GravaStar!

Whereas the Anker 713 Charger is nice for most individuals, a few of you want extra out of your wall charger. Listed below are some scorching offers we additionally discovered as we speak.

If you need essentially the most energy attainable, the UGREEN Nexode Professional 160W USB-C Charger has a max output of 160W and might cost a single system at a most of 140W. It additionally has sufficient ports to cost 4 gadgets directly. You may decide this one up for $102, down from $120. The one caveat is that the deal is simply out there for Prime subscribers.

When you favor one thing a bit extra enjoyable, the UGREEN Uno Charger 65W can also be 28% off, bringing the fee all the way down to $36. It has two USB-C ports, a USB-A port, and a 65W max output. To not point out, it is among the coolest chargers we’ve seen! Sadly, this provide can also be solely out there to Amazon Prime prospects.

The GravaStar Alpha65 GaN 65W Wall Charger is on the market to everybody for simply $35. Its options are practically equivalent to these of the UGREEN Uno Charger 65W. It additionally has two USB-C ports, a USB-A connection, and a 65W output. The robotic design can also be rather more aggressive and anime-styled, although a few of you would possibly favor it.