I have been playing some flight sims and have noticed that in some of them you get wing flex during hard landings. Is it realistic? Can wings flex upon a hard landing?
Yes, when the wheels touch down the wings still have a negative vertical velocity component and they sag down dynamically, and then rebound back up again to a constant value of "static" sag that reflects the weight of the wing and its stiffness.
In the C-5 heavy transport, the touchdown sag was sufficient to "eat up" the fatigue design margin in the huge wing attachment structure which transferred wing lift to the fuselage, causing premature cracking. This required a significant redesign and retrofit work on that "box structure" to allow the C-5 airframe to meet its design lifetime goals.
At one point, the Air Force considered using active thrust vectoring from the engines to "prop up" the wing during landings and thereby reduce the magnitude of flexure. One of my engineering professors worked on a dynamic model of C-5 wing flexure stresses and strains during touchdown sag to see if tipping the engine exhaust stream downwards was a viable solution to the problem.
Are you talking about bouncing up and down or "remaining sagged"?
For the first one, oftentimes upon (hard) touchdowns, there is some bouncing.
For the second one, the wings remain "sagged" while producing lift.
If there is still noticeable airspeed, the wing will still be producing lift, so there will be some "sagging" indeed.
BUT as soon as the spoilers are activated, (most) lift gets spoiled and the wings stop flexing.
It's actually very cool to see how the wings drop as soon as the spoilers are deployed.
The sag of the wings is particularly apparent, if you sit in a window seat near the wings.
The following pictures were taken from the lower deck of an A-380 in-flight during the approach and later post-flight on the ground.
Notive, that in-flight, the root of the wing-tip is visible, while post-flight, only a portion of the wing-tip can be seen.
Structures like aircraft wings and even bridges are quite rigid, but not totally. There is always some strain in response to stress (stretching in tension or compressing in, well, compression). Bending loads are basically just tension on one side and compression on the other, so bending loads result in, well, bending. Structures that are extremely rigid are often brittle - in other words, they tend to fracture before exhibiting much, if any strain. The visible flexing of an aircraft wing is generally a good thing, because it is a more forgiving response to high levels of stress than a sudden brittle fracture. The only downside to a lot of flex is the possibility of harmonic resonance, in which oscillations can build up in intensity and overload the structure (in wings, it is known as flutter). Aircraft wings are designed to allow for some flex to provide a forgiving response to high stresses, while remaining stiff enough to avoid flutter.
On a hard landing, the wing unload its lift abruptly, so the upward flex it had under flight loads is suddenly relieved, but the vertical velocity of the aircraft is suddenly arrested by the landing gear as it contacts the runway; the wings do have mass, and thus inertia, so want to keep moving downward even as the rest of the aircraft's vertical velocity is canceled by touchdown. Put all that together, and the wings will always appear to flex downward on landing, it's just more pronounced on a hard landing.
If you get many chances to fly on an airliner, sometimes sit behind the wings, and enjoy looking out the window, you will quickly learn that the wings flex all the time. They are long and fairly thin, and all materials have some give. During turbulence the flexing can be quite visible. I think you can see it during landings too.